1、復(fù)制專題地址和url地址 [php] <input type="button" name="anniu1" onClick='copyToClipBoard()' value="復(fù)制地址"> <script language="javascript"> ?? function copyToClipBoard(){ ??? var clipBoardContent=""; ??? clipBoardContent+=document.title; ??? clipBoardContent+=""; ??? clipBoardContent+=this.location.href; ??? window.clipboardData.setData("Text",clipBoardContent); ??? alert("復(fù)制成功!"); } </script>[/php] ? 2、復(fù)制url地址 [php] <input type="button" name="anniu2" onClick='copyUrl()' value="復(fù)制URL地址"> <script language="javascript"> ?? function copyUrl() ?? { ??? var clipBoardContent=this.location.href; ??? window.clipboardData.setData("Text",clipBoardContent); ??? alert("復(fù)制成功!"); ?? } </script> ?[/php] 3、點(diǎn)擊文本框時,復(fù)制文本框里面的內(nèi)容 [php] <input onclick="oCopy(this)" value="你好.要copy的內(nèi)容!"> <script language="javascript"> function oCopy(obj){ obj.select(); js=obj.createTextRange(); js.execCommand("Copy") alert("復(fù)制成功!"); } </script>[/php] ? 4、復(fù)制文本框或者隱藏域中的內(nèi)容 [php] <script language="javascript"> function CopyUrl(target){ target.value=myimg.value; target.select();?? js=myimg.createTextRange();?? js.execCommand("Copy"); alert("復(fù)制成功!"); } function AddImg(target){ target.value="[IMG]"+myimg.value+"[/ img]"; target.select(); js=target.createTextRange();?? js.execCommand("Copy"); alert("復(fù)制成功!"); } </script> <input name=myimg type=hidden id=myimg value="<a href="http://0597seo.com/">http://0597seo.com</a>" /> <input name=imgurl type=text size=32 value="<a href="http://0597seo.com/">http://0597seo.com</a>" /> <input type=button value="點(diǎn)擊這里復(fù)制本站地址" onclick="CopyUrl(imgurl);" /> [/php] 5、復(fù)制span標(biāo)記中的內(nèi)容 [php] <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); alert("復(fù)制成功!"); } </script> [/php] 以下是代碼片段: [php] <br /> <br /> <span id="tbid">http://0597seo.com</span>?? [<a href="#" onclick="copyText(document.all.tbid)">點(diǎn)擊復(fù)制</a>]<br/><br/> <span id="tbid2">http://0597seo.com</span>?? [<a href="#" onclick="copyText(document.all.tbid2)">點(diǎn)擊復(fù)制</a>]<br/><br/> [/php]
發(fā)表評論