JS:復制內容到剪貼板(無插件,兼容所有瀏覽器)


<button onclick="copyToClip('內容')"> Copy </button>
/**
 * 復制內容到粘貼板
 * content : 需要復制的內容
 * message : 復制完后的提示,不傳則默認提示"復制成功"
 */
function copyToClip(content, message) {
    var aux = document.createElement("input"); 
    aux.setAttribute("value", content); 
    document.body.appendChild(aux); 
    aux.select();
    document.execCommand("copy"); 
    document.body.removeChild(aux);
    if (message == null) {
        alert("復制成功");
    } else{
        alert(message);
    }
}

 


免責聲明!

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



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