原生javascrip 复制功能
兼容chrome FIrfox IE
下载地址
代码如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>My sql</title> </head> <body> <style type="text/css"> #newtext {position: absolute;top: 0;left: 0;opacity: 0;z-index: -10;} </style> <span id="wenzi">I love you!!!</span> <input id="newtext" value=""> <button type="button" onclick="fuzhi()">Copy Link</button> <script type="text/javascript"> function fuzhi(){ var newtext=document.getElementById("newtext"); var wenzi=document.getElementById("wenzi").innerText; newtext.value=wenzi; newtext.select(); // 选择对象 document.execCommand("Copy"); // 执行浏览器复制命令 alert("Copy Successfull"); } </script> </body> </html>