js点击复制代码

 1.点击复制标题和地址的代码:
<title>标题</title>
<input type="button" name="Submit" onClick='copyToClipBoard()' value="复制专题地址,传给QQ/MSN上的好友">
<script language="javascript">
   function copyToClipBoard(){
    var clipBoardContent="";
    clipBoardContent+=document.title;
    clipBoardContent+="";
    clipBoardContent+=this.location.href;
    window.clipboardData.setData("Text",clipBoardContent);
    alert("复制成功,请粘贴到你的QQ/MSN上推荐给你的好友");
}
</script>

2.点击复制文本框内容的代码:
<script>
function oCopy(obj){
obj.select();
js=obj.createTextRange();
js.execCommand("Copy")
}
</script>

<input οnclick="oCopy(this)" value="要copy的内容!">

3.点击复制网址推荐给好友的代码:
<script language="javascript">
function CopyUrl(target){
target.value=myimg.value;
target.select();
js=myimg.createTextRange();
js.execCommand("Copy");
}
function AddImg(target){
target.value="[IMG]"+myimg.value+"[/ img]"; (注:[/ img]中/后面有空格请去掉 )
target.select();
js=target.createTextRange();
js.execCommand("Copy");
}
</script>
<input name=myimg type=hidden id=myimg value="http://www.hooyes.com/" />
<input name=imgurl type=text size=32 value="http://www.hooyes.com/" />

<input type=button value="点击这里复制本站地址" οnclick="CopyUrl(imgurl);" />
<P>如果你喜欢本站,就推荐给你的朋友吧!</P>

4.点击复制网址2
<script type="text/javascript">
function copyText(obj)
{
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);}
</script>
以下是代码片段:
<span id="tbid">http://www.hooyes.com</span>
[<a href="#" οnclick="copyText(document.all.tbid)">点击复制</a>]<br/><br/>
<span id="tbid2">http://www.hooyes.com </span>
[<a href="#" οnclick="copyText(document.all.tbid2)">点击复制</a>]<br/><br/>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值