用 javascript 实现的点击复制代码


<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>

<script>
function oCopy(obj){
obj.select();
js=obj.createTextRange();
js.execCommand("Copy")
}
</script>
<input onclick="oCopy(this)" value="要copy的内容!">

<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.phpstudy.net" />
<input name=imgurl type=text size=32 value="http://www.phpstudy.net" />
<input type=button value="点击这里复制本站地址" onclick="CopyUrl(imgurl);" />
<P>如果你喜欢本站,就推荐给你的朋友吧!</P>

<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.phpstudy.net</span>
[<a href="#" onclick="copyText(document.all.tbid)">点击复制</a>]<br/><br/>
<span id="tbid2">http://www.phpstudy.net</span>
[<a href="#" onclick="copyText(document.all.tbid2)">点击复制</a>]<br/><br/>


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3