zeroclipboard 單個(gè)復(fù)制按鈕和多個(gè)復(fù)制按鈕的實(shí)現(xiàn)方法
zeroclipboard下載地址:http://www.dbjr.com.cn/jiaoben/24961.html
zeroclipboard實(shí)現(xiàn)多瀏覽器復(fù)制到粘貼板功能(單個(gè)復(fù)制按鈕和多個(gè)復(fù)制按鈕) 為了更好的用戶體驗(yàn),現(xiàn)在很多網(wǎng)站中文本框的內(nèi)容只需要點(diǎn)擊復(fù)制按鈕這樣就能把內(nèi)容復(fù)制到粘貼板了;
出于兼容性的考慮,基本上都是通過zeroclipboard來實(shí)現(xiàn).首先要下載zeroclipboard,解壓后把ZeroClipboard.js和ZeroClipboard.swf、ZeroClipboard10.swf(“為了flash10”)放到項(xiàng)目中,可以通過ZeroClipboard.setMoviePath( '/ZeroClipboard.swf' )方法來加載swf;
下面是整理的代碼(也是通過 網(wǎng)上查找整理的)
(單個(gè)復(fù)制按鈕):
html:
<input type="text" value="text" id="copy_txt"/><a href="javascirpt:;" id="copy_btn">復(fù)制</a>
<script language="JavaScript">
ZeroClipboard.setMoviePath( 'ZeroClipboard.swf' ); //和html不在同一目錄需設(shè)置setMoviePath
ZeroClipboard.setMoviePath( 'ZeroClipboard10.swf' );
var clip = new ZeroClipboard.Client(); //創(chuàng)建新的Zero Clipboard對象
clip.setText( '' ); // will be set later on mouseDown //清空剪貼板
clip.setHandCursor( true ); //設(shè)置鼠標(biāo)移到復(fù)制框時(shí)的形狀
clip.setCSSEffects( true ); //啟用css
clip.addEventListener( 'complete', function(client, text) { //復(fù)制完成后的監(jiān)聽事件
alert("aa")
clip.hide(); // 復(fù)制一次后,hide()使復(fù)制按鈕失效,防止重復(fù)計(jì)算使用次數(shù)
} );
clip.addEventListener( 'mouseDown', function(client) {
clip.setText( document.getElementById('copy_txt').value );
} );
clip.glue( 'copy_btn' );
</script>
多個(gè)復(fù)制按鈕:
<input type="text" value="text" id="copy_txt0"/><a href="javascirpt:;" id="copy_btn0" data='0' class="copyBtn">復(fù)制</a>
<input type="text" value="text" id="copy_txt1"/><a href="javascirpt:;" id="copy_btn1" data='1' class="copyBtn">復(fù)制</a>
<input type="text" value="text" id="copy_txt2"/><a href="javascirpt:;" id="copy_btn2" data='2' class="copyBtn">復(fù)制</a>
<script language="JavaScript">
$(".copyBtn").each(function(i){
var id = $(this).attr('data');
var clip=null;
clip = new ZeroClipboard.Client();
ZeroClipboard.setMoviePath( 'ZeroClipboard.swf' ); //和html不在同一目錄需設(shè)置setMoviePath
ZeroClipboard.setMoviePath( 'ZeroClipboard10.swf' );
clip.setHandCursor( true );
clip.setText( $("#copy_txt"+id).val() );
clip.addEventListener('complete', function (client, text) {
alert( "恭喜復(fù)制成功" );
});
clip.glue( 'copy_btn'+id);
});
</script>
注意: clip.setText( $("#copy_txt"+id).val() );如果是獲取div中的內(nèi)容, 一般用clip.setText( $("#copy_txt"+id).text() );或clip.setText( $("#copy_txt"+id).html() );
- 瀏覽器復(fù)制插件zeroclipboard使用指南
- ZeroClipboard插件實(shí)現(xiàn)多瀏覽器復(fù)制功能(支持firefox、chrome、ie6)
- 使用ZeroClipboard解決跨瀏覽器復(fù)制到剪貼板的問題
- zeroclipboard復(fù)制到剪切板的flash
- js 剪切板應(yīng)用clipboardData詳細(xì)解析
- js復(fù)制到剪切板的實(shí)例方法
- js 剪切板的用法(clipboardData.setData)與js match函數(shù)介紹
- JS將制定內(nèi)容復(fù)制到剪切板示例代碼
- Js+Flash實(shí)現(xiàn)訪問剪切板操作
- JavaScript使用ZeroClipboard操作剪切板
相關(guān)文章
JavaScript 短路運(yùn)算的實(shí)現(xiàn)
本文主要介紹了JavaScript 短路運(yùn)算的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06JavaScript比較當(dāng)前時(shí)間是否在指定時(shí)間段內(nèi)的方法
這篇文章主要介紹了JavaScript比較當(dāng)前時(shí)間是否在指定時(shí)間段內(nèi)的方法,涉及javascript時(shí)間與字符串的轉(zhuǎn)換及比較操作相關(guān)技巧,需要的朋友可以參考下2016-08-08JSON.parse()和JSON.stringify()使用介紹
這篇文章主要介紹了JSON.parse()和JSON.stringify()使用,需要的朋友可以參考下2014-06-06用canvas 實(shí)現(xiàn)個(gè)圖片三角化(LOW POLY)效果
這篇文章主要介紹了用canvas 實(shí)現(xiàn)個(gè)圖片三角化(LOW POLY)效果 的相關(guān)資料,需要的朋友可以參考下2016-02-02javascript 用原型繼承來實(shí)現(xiàn)對象系統(tǒng)
對象系統(tǒng)中的繼承特性有三種方式:基于類,基于原型,基于元類2010-03-03