<html>
<head>
<title>JS复制</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function copyText(id) {
var targetText = document.getElementById(id);
try {
var clipText = targetText.createTextRange();
clipText.execCommand("Copy");
alert('复制成功,可以按Ctrl+V粘贴');
} catch(e) {
targetText.focus();//获得焦点
targetText.select();//选中文本
alert('您的浏览器不支持剪贴板复制,\n请按Ctrl+C复制链接。');
}
}
</script>
</head>
<body>
<div>
<input id="shareUrl" value="http://chenfeng0104.iteye.com" style="width:260px;"/>
<input type="button" value="Copy" onclick="copyText('shareUrl');"/>
</div>
</body>
</html>
<head>
<title>JS复制</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function copyText(id) {
var targetText = document.getElementById(id);
try {
var clipText = targetText.createTextRange();
clipText.execCommand("Copy");
alert('复制成功,可以按Ctrl+V粘贴');
} catch(e) {
targetText.focus();//获得焦点
targetText.select();//选中文本
alert('您的浏览器不支持剪贴板复制,\n请按Ctrl+C复制链接。');
}
}
</script>
</head>
<body>
<div>
<input id="shareUrl" value="http://chenfeng0104.iteye.com" style="width:260px;"/>
<input type="button" value="Copy" onclick="copyText('shareUrl');"/>
</div>
</body>
</html>