<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style> .put{ border:none; outline: none; position: absolute; top:-100px; } p{ user-select: none; } </style> </head> <body> <input class="put" type="text" value="20041016"> <p>20041016</p> <button onclick="fn()">复制</button> <script> let put = document.getElementsByClassName('put')[0]; function fn(){ put.select(); document.execCommand("copy"); } </script> </body> </html>