JS一键复制实现

JS实现一键复制操作

 function copy(text) {

     // chrome 和 IE都可以使用
     var textArea = document.createElement("textarea");
     document.body.appendChild(textArea);

     textArea.style.position = "absolute";
     textArea.style.left = "-9999px";
     textArea.style.top = "-1000px";
     textArea.value = text;

     textArea.select();
     document.execCommand("Copy");
     document.body.removeChild(textArea);
 }


 function copyIE(text) {

     //  只有IE支持这个方法
     window.clipboardData.clearData();
     window.clipboardData.setData("Text", text);

 }

猜你喜欢

转载自blog.csdn.net/qq_28949081/article/details/82824690