<textarea id="pushUrlsTxt" rows="5" cols="55"></textarea> <a href="javascript:void(0);" class="modal-button-center" onClick="copyPushUrl()">复制URL</a> <script> 1.实现点击按钮,复制文本框中的的内容 copyPushUrl(){
var Url=document.getElementById("pushUrlsTxt");
Url.select(); // 选择对象
document.execCommand("Copy"); // 执行浏览器复制命令
alert("复制成功");
} 2.复制专题地址和 url 地址,传给 QQ/MSN 上的好友 function copyToClipBoard(){
var clipBoardContent="";
clipBoardContent+=document.title;
clipBoardContent+="";
clipBoardContent+=this.location.href;
window.clipboardData.setData("Text",clipBoardContent);
alert("复制成功,请粘贴到你的QQ/MSN上推荐给你的好友");
} 3.点击文本框时,复制文本框里面的内容 function copy(obj){//obj指代需要copy的对象 obj.select(); js = obj.createTextRange(); js.execCommand("copy"); alert("copy success!"); } 4.复制文本框或者隐藏域中的内容 function copyurl(target){ target.value = myimg.value; target.select(); js = myimg.createTextRange(); js.execCommand("copy"); alert("copy success!"); } function addimg(target){ target.value ="[IMG]"+ myimg.value+"[/img]"; target.select(); js = target.createTextRange(); js.execCommand("copy"); alert("copy success!"); } 5.复制 span 标记中的内容 function copytext(obj){ var target= document.body.createTextRange(); target.moveToElementText(obj); target.scrollIntoView(); target.select(); target.execCommand("copy"); target.collapse(false); alert("copy success!"); } </script>