abstract:項(xiàng)目中突然需要使用復(fù)制功能,在網(wǎng)上搜索了下看到了ZeroClipboard插件,好用,但是也有局限。用法如下:1、引用jquery、zclip.js、swf文件。demo地址:https://github.com/chaoli920029342/jquery_copy2、初始化<body> <input type="text" name=&
項(xiàng)目中突然需要使用復(fù)制功能,在網(wǎng)上搜索了下看到了ZeroClipboard插件,好用,但是也有局限。用法如下:
1、引用jquery、zclip.js、swf文件。
demo地址:https://github.com/chaoli920029342/jquery_copy
2、初始化
<body> <input type="text" name="text" id="text" value="http://www.baidu.com" /> <a href="javascript:void(0)" rel="external nofollow" id="dynamic">復(fù)制</a> <script type="text/javascript"> $(document).ready(function(){ $("#dynamic").zclip({ path:'ZeroClipboard.swf', copy:$('#text').val(), beforeCopy:function(){ //some code }, afterCopy:function(){ alert($("#text").val()); } }); //beforeCopy afterCopy 是可選項(xiàng) }); </script> </body>
注:
1、需在服務(wù)器上運(yùn)行 localhost
2、js+swf實(shí)現(xiàn),文件需要同時引入。 ZeroClipboard提供一個透明的flash,用于和剪切版交互,當(dāng)點(diǎn)擊頁面上的“復(fù)制”按鈕時,將需要的內(nèi)容傳入Flash,再通過Flash的復(fù)制功能把傳入的內(nèi)容復(fù)制到剪貼板。 需保證該flash被正確加載即可。
3、可兼容各大瀏覽器
更多關(guān)于jQuery實(shí)現(xiàn)復(fù)制到粘貼板功能請關(guān)注PHP中文網(wǎng)(ipnx.cn)其他文章!