<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>点击按钮时将选中文字复制</title> </head> <body> <h2>我是H2标签</h2> <input type="button" onclick="copy()" value="点击后复制鼠标左键选中的文字"> <input type="text" placeholder="ctrl + v或右键粘贴"> <script> function copy(){ document.execCommand("Copy"); } </script> </body> </html>