如何用JavaScript复制到剪贴板

时间:2021-01-06 19:35:20
 1 <!DOCTYPE HTML>
2 <html lang="en-US">
3 <head>
4 <meta charset="UTF-8">
5 <title></title>
6 <script type="text/javascript" src="./jquery.min.js"></script>
7 </head>
8 <body>
9 <textarea name="" id="demo" cols="30" rows="10">测试的一段文本内容1234564</textarea>
10
11 <a href="javascript:void(0);" onclick="copyToClipboard(document.getElementById('demo').innerHTML)" title="复制">
12 <img src="./copycode.gif" alt="复制">
13 </a>
14 </body>
15 <script type="text/javascript">
16 function copyToClipboard(text){
17 window.prompt("按 Ctrl+C 复制内容", text);
18 }
19 </script>
20 </script>
21 </html>

如何用JavaScript复制到剪贴板如何用JavaScript复制到剪贴板