<body>
<input type="text" id="url" value = "http://www.baidu.com"> <button type = "button" id = "btn">点我复制</button>
<script type="text/javascript">
window.onload = function () {
var btn = document.getElementById("btn");
var url = document.getElementById("url");
btn.onclick = function (){
url.select();
document.execCommand("Copy");
}
}
</script>
<input type="text" id="url" value = "http://www.baidu.com"> <button type = "button" id = "btn">点我复制</button>
<script type="text/javascript">
window.onload = function () {
var btn = document.getElementById("btn");
var url = document.getElementById("url");
btn.onclick = function (){
url.select();
document.execCommand("Copy");
}
}
</script>
</body>
其中,execCommand方法是执行一个对当前文档,当前选择或者给出范围的命令。具体用法及参数详情请参考点击打开链接