js 一键复制至剪切板

3,014 阅读1分钟

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 兼容