|
本帖最后由 OK论坛 于 2024-8-8 15:45 编辑
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <button id="btn">复制</button>
- <body>
- </body>
- <script>
- const btn = document.querySelector("#btn");
- btn.addEventListener("click", () => {
- try {
- navigator.clipboard.writeText("这里是要复制内容");
- console.log("复制成功");
- } catch (err) {
- console.log("复制失败", err);
- }
- })
- </script>
- </html>
复制代码
|
|