1 <html>
2 <head>
3
4 <script type="text/javascript">
5 function copyText() {
6 var text = document.getElementById("text").innerText;
7 var input = document.getElementById("input");
8 input.value = text; // 修改文本框的内容
9 input.select(); // 选中文本
10 document.execCommand("copy"); // 执行浏览器复制命令
11 alert("复制成功");
12 }
13 script>
14
15 <style type="text/css">
16 .wrapper {
17 position: relative;
18 }
19 #input {
20 position: absolute;
21 top: 0;
22 left: 0;
23 opacity: 0;
24 z-index: -10;
25 }
26 style>
27 head>
28
29 <body>
30 <div class="wrapper">
31 <p id="text">我把你当兄弟你却想着复制我?p>
32 <textarea id="input">这是幕后黑手textarea>
33 <button onclick="copyText()">copybutton>
34 div>
35 body>
36 html>