html代码:
<div>
<span id="copyMy"> 复制我试试</span>
<button onClick="copyFn()">点击复制</button>
</div>
jsdaima:
<script>
function copyFn() {
var val = document.getElementById('copyMy');
window.getSelection().selectAllChildren(val);
document.execCommand("Copy");
alert("已复制好,可贴粘。");
}
</script>