H5/纯JS实现:把网页中的文字复制到剪切板
const dom = document.getElementById(`span1`) const selection = window.getSelection() const range = document.createRange() // 选择复制目标 range.selectNodeContents(dom) selection.removeAllRanges() selection.addRange(range) // 已复制文字 console.log(‘selectedText‘, selection.toString()) // 执行复制 document.execCommand(‘copy‘) // 去除所有选中,否则该元素会显示为 被选中的颜色 selection.removeAllRanges()
H5/纯JS实现:把网页中的文字复制到剪切板
,温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/42504.html
- 上一篇:如何画思维导图?利用在线网站绘制思维导图怎样操作
- 下一篇:apache虚拟主机配置