JS实现复制功能的方法
作者:互联网
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>JS实现复制功能的方法 </title> </head> <script type="text/javascript"> function copyText(){ var text = document.getElementById("example") text.select()//选择对象 document.execCommand("Copy") //执行浏览器复制命令 console.log("已复制,可粘贴"); } </script> <body> <div> <p>please input text</p> <textarea cols="60" rows="10" placeholder="please input text" id="example"> </textarea> </div> <input type="button" onClick="copyText()" value="click copy text"> </body> </html>
标签:功能,选择对象,text,JS,复制,document,select 来源: https://www.cnblogs.com/boye169/p/15409762.html