JS简单函数实现页面元素文本复制功能
😂 这篇文章最后更新于1498天前,您需要注意相关的内容是否还可用。
JS
function copywx() { const range = document.createRange(); range.selectNode(document.getElementById('copy_content')); const selection = window.getSelection(); if (selection.rangeCount > 0) selection.removeAllRanges(); selection.addRange(range); document.execCommand('copy'); alert("复制成功!") }
其中可以打印range出来看看复制的内容。
留言评论
暂无留言