<div id="copy-txt">内容内容</div>
<button type="submit" onclick="copyTXT()"></button>
function copyTXT(){
var copyDOM = document.querySelector("#copy-txt"); //指定的DOM元素
var range = document.createRange(); // 创建容器
range.selectNode(copyDOM); // 选中需要复制的节点
window.getSelection().addRange(range); // 执行选中元素
var successful = document.execCommand('copy');// 执行 copy 操作
try{
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copy was ' + msg);
}catch(err) {
console.log('unable to copy');
}
window.getSelection().removeAllRanges(); // 移除选中的元素
}