最后我的解决方案是,在页面中添加一个 div,手动写入内容innerHTML,然后把它隐藏掉
function copy(targetDom) {
let range = document.createRange();
range.selectNode(hiddenErrcode);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
}
复制代码
转载于:https://juejin.im/post/5d492adff265da03e05afa9d