js實現復制功能兼容ios


html:

<div id="copyBT">這是要復制的1內容</div>

<a id="contentas">這是復制按鈕</a>

js:

   function copyArticle() {
                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);

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM