const copy = (copyText: string)=>{
const element = document.createElement('span');
element.textContent = copyText;
document.body.appendChild(element);
const range = document.createRange && document.createRange();
const selection = window.getSelection && window.getSelection();
if (range && selection) {
range.selectNode(element);
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('Copy');
element.remove && element.remove();
alert('复制成功');
} else {
alert('您使用的浏览器暂不支持自动复制,请更换Chrome浏览器进行操作或者使用鼠标复制');
}
}
浏览器复制文本
最新推荐文章于 2022-09-19 09:39:39 发布