<body>
<button>copy value</button>
</body>
<script>
var dom = document.querySelector('button')
dom.onclick = function () {
copyEvent(this)
}
// 复制内容到截切版
function copyEvent (el) {
window.getSelection().selectAllChildren(el) // 选中数据
document.execCommand('Copy')
document.activeElement.blur()
window.getSelection().removeAllRanges()
}
</script>