動態生成的DOM不會觸發onclick事件的原因及解決方法
634
2024-02-22
本文實例講述了Zero Clipboard實現瀏覽器復制到剪貼板的方法。分享給大家供大家參考,具體如下:
<script type="text/javascript" src="http://www.gimoo.net/t/1903/{$site_url}/Public/js/ZeroClipboard.js"></script> <script language="JavaScript"> $(function(){ $(".my_clip_button").each(function(i){ var id = $(this).attr('data'); var clip=null; clip = new ZeroClipboard.Client(); ZeroClipboard.setMoviePath("{$site_url}/Public/js/ZeroClipboard.swf"); //設置 不然要放在網站根目錄下才顯示 clip.setHandCursor( true ); clip.setText( $("#txtInvite_"+id).val() ); clip.addEventListener('complete', function (client, text) { ui.success( "恭喜復制成功" ); }); clip.glue( 'd_clip_button_'+id ,'d_clip_container_'+id ); }); }); </script> <style> .my_clip_button { width:62px; text-align:center; height:20px;border:1px solid black; background-color:#ccc; margin:2px; padding:2px; cursor:default; font-size:9pt; } .my_clip_button.hover { background-color:#eee; } .my_clip_button.active { background-color:#aaa; } </style> <div style="width:90%;margin:0 auto; height:50px;line-height:20px;"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="19%" height="45" align="right">默認邀請鏈接:</td> <td width="52%"><input type="text" name="txtInvite_default" id="txtInvite_default" value="{$defaultInviteLink}" style="width:350px;" /></td> <td width="31%"> <div id="d_clip_container_default" style="position:relative;"> <div id="d_clip_button_default" class="my_clip_button" data="default">復制</div> </div> </td> </tr> </table> </div> <volist name="invitelists" id="vo"> <div style="width:90%;margin:0 auto; height:50px;line-height:20px;"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="19%" height="45" align="right">{$vo.group_name}專用邀請鏈接:</td> <td width="52%"><input type="text" name="txtInvite_{$vo.id}" id="txtInvite_{$vo.id}" value="{$vo.invitelink}" style="width:350px;" /></td> <td width="31%"> <div id="d_clip_container_{$vo.id}" style="position:relative;"> <div id="d_clip_button_{$vo.id}" class="my_clip_button" data="{$vo.id}">復制</div> </div> </td> </tr> </table> </div> </volist>
更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery拖拽特效與技巧總結》、《jQuery擴展技巧總結》、《jQuery常見經典特效匯總》、《jQuery動畫與特效用法總結》、《jquery選擇器用法總結》及《jQuery常用插件及用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
#免責聲明#
本站[綠夏技術導航]提供的一切軟件、教程和內容信息僅限用于學習和研究目的;不得將上述內容用于商業或者非法用途,否則,一切后果請用戶自負。本站信息來自網絡收集整理,版權爭議與本站無關。您必須在下載后的24個小時之內,從您的電腦或手機中徹底刪除上述內容。如果您喜歡該程序或內容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權問題,如有侵權請郵件[admin@lxwl520.com]與我們聯系進行刪除處理。敬請諒解!