js点击复制代码
?1.點(diǎn)擊復(fù)制標(biāo)題和地址的代碼:
<title>標(biāo)題</title>
<input type="button" name="Submit" onClick='copyToClipBoard()' value="復(fù)制專題地址,傳給QQ/MSN上的好友">
<script language="javascript">
?? function copyToClipBoard(){
??? var clipBoardContent="";
??? clipBoardContent+=document.title;
??? clipBoardContent+="";
??? clipBoardContent+=this.location.href;
??? window.clipboardData.setData("Text",clipBoardContent);
??? alert("復(fù)制成功,請(qǐng)粘貼到你的QQ/MSN上推薦給你的好友");
}
</script>
2.點(diǎn)擊復(fù)制文本框內(nèi)容的代碼:
<script>
function oCopy(obj){
obj.select();
js=obj.createTextRange();
js.execCommand("Copy")
}
</script>
<input οnclick="oCopy(this)" value="要copy的內(nèi)容!">
3.點(diǎn)擊復(fù)制網(wǎng)址推薦給好友的代碼:
<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]中/后面有空格請(qǐng)去掉 )
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="點(diǎn)擊這里復(fù)制本站地址" οnclick="CopyUrl(imgurl);" />
<P>如果你喜歡本站,就推薦給你的朋友吧!</P>
4.點(diǎn)擊復(fù)制網(wǎng)址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)">點(diǎn)擊復(fù)制</a>]<br/><br/>
<span id="tbid2">http://www.hooyes.com </span>
[<a href="#" οnclick="copyText(document.all.tbid2)">點(diǎn)擊復(fù)制</a>]<br/><br/>
總結(jié)
- 上一篇: R400换XP 所有驱动程序安装一览表
- 下一篇: CSS教程:li和ul标签用法举例