1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title></title> 5 <script type="text/javascript"> 6 function copyUrl2() 7 { 8 var Url2=document.getElementById("biao1").innerText; 9 var oInput = document.createElement('input'); 10 oInput.value = Url2; 11 document.body.appendChild(oInput); 12 oInput.select(); // 选择对象 13 document.execCommand("Copy"); // 执行浏览器复制命令 14 oInput.className = 'oInput'; 15 oInput.style.display='none'; 16 alert('复制成功'); 17 } 18 </script> 19 </head> 20 <body> 21 22 <div cols="20" id="biao1">12345678</div> 23 <input type="button" onClick="copyUrl2()" value="点击复制代码" /> 24 </body> 25 </html>