<!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>