Home >Web Front-end >JS Tutorial >Zero Clipboard implements the browser's method of copying to the clipboard (multiple copy buttons)_jquery
The example in this article describes how Zero Clipboard implements browser copying to the clipboard. Share it with everyone for your reference, the details are as follows:
<script type="text/javascript" src="{$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>
Readers who are interested in more jQuery-related content can check out the special topics on this site: "JQuery drag effects and techniques summary", "jQuery extension techniques summary", "JQuery common classic special effects summary", "jQuery animation and special effects usage summary", "jquery selector usage summary" and "jQuery common plug-ins and usage Summary》
I hope this article will be helpful to everyone in jQuery programming.