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

相关文章
相关标签/搜索