js復制span內容到剪切板


<span id="copyText">123456</span>

<span onclick="copy();">復制</span>

 

function copy() {

var text =document.getElementById("copyText").innerText;

var input = document.createElement('input'); input.setAttribute('id', 'copyInput');

input.setAttribute('value', text);

document.getElementsByTagName('body')[0].appendChild(input);

document.getElementById('copyInput').select();

document.execCommand('copy')) 

alertinfo('復制成功');

document.getElementById('copyInput').remove();

}


免責聲明!

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



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