1 <textarea id="pushUrlsTxt" rows="5" cols="55"></textarea> 2 3 <a href="javascript:void(0);" class="modal-button-center" onClick="copyPushUrl()">复制URL</a> 4 5 <script> 6 7 1.实现点击按钮,复制文本框中的的内容 8 9 copyPushUrl(){ 10 var Url=document.getElementById("pushUrlsTxt"); 11 Url.select(); // 选择对象 12 document.execCommand("Copy"); // 执行浏览器复制命令 13 alert("复制成功"); 14 } 15 16 17 18 2.复制专题地址和 url 地址,传给 QQ/MSN 上的好友 19 20 function copyToClipBoard(){ 21 var clipBoardContent=""; 22 clipBoardContent+=document.title; 23 clipBoardContent+=""; 24 clipBoardContent+=this.location.href; 25 window.clipboardData.setData("Text",clipBoardContent); 26 alert("复制成功,请粘贴到你的QQ/MSN上推荐给你的好友"); 27 } 28 29 30 31 3.点击文本框时,复制文本框里面的内容 32 33 function copy(obj){//obj指代需要copy的对象 34 35 obj.select(); 36 37 js = obj.createTextRange(); 38 39 js.execCommand("copy"); 40 41 alert("copy success!"); 42 43 } 44 45 4.复制文本框或者隐藏域中的内容 46 47 function copyurl(target){ 48 49 target.value = myimg.value; 50 51 target.select(); 52 53 js = myimg.createTextRange(); 54 55 js.execCommand("copy"); 56 57 alert("copy success!"); 58 59 } 60 61 function addimg(target){ 62 63 target.value ="[IMG]"+ myimg.value+"[/img]"; 64 65 target.select(); 66 67 js = target.createTextRange(); 68 69 js.execCommand("copy"); 70 71 alert("copy success!"); 72 73 } 74 75 5.复制 span 标记中的内容 76 77 function copytext(obj){ 78 79 var target= document.body.createTextRange(); 80 81 target.moveToElementText(obj); 82 83 target.scrollIntoView(); 84 85 target.select(); 86 87 target.execCommand("copy"); 88 89 target.collapse(false); 90 91 alert("copy success!"); 92 93 } 94 95 </script>