js 一鍵複製至剪切板

html

<textarea name="" id="copytest" readonly>一鍵複製至剪切版</textarea>
 <input type="button" id="copy" value="複製">
複製代碼

js

$(document).on("click","#copy",function(){
    var copytest=$("#copytest");
    copytest.select();
    document.execCommand("copy");
    alert("已複製到剪切板");
})
複製代碼

execCommand 兼容

相關文章
相關標籤/搜索