美文网首页
js实现复制功能兼容ios

js实现复制功能兼容ios

作者: 凉柠_da5d | 来源:发表于2019-01-11 16:59 被阅读0次

js

function copyArticle(event) { const range = document.createRange(); range.selectNode(document.getElementById('copyBT')); const selection = window.getSelection(); if(selection.rangeCount > 0) selection.removeAllRanges(); selection.addRange(range); document.execCommand('copy'); alert("复制成功") } document.getElementById('contentas').addEventListener('click', copyArticle, false);

dom

<div id="copyBT">这是要复制的1内容</div>

<a id="contentas">这是复制按钮</a>

相关文章

网友评论

      本文标题:js实现复制功能兼容ios

      本文链接:https://www.haomeiwen.com/subject/cbnxdqtx.html