Zeroclipboard多个元素

我在代码中创建多个Zeroclipboard实例化时遇到问题,每个实例化在调用后都会启动一个弹出窗口。

FRSDE3RD FRSDE3RD2 FRSDE3RD3 $(document).ready(function(){ ZeroClipboard.setMoviePath( 'path/to/swf/ZeroClipboard.swf' ); // setup single ZeroClipboard object for all our elements clip = new ZeroClipboard.Client(); clip.setHandCursor( true ); // assign a common mouseover function for all elements using jQuery $('a.xxx').mouseover( function() { // set the clip text to our innerHTML var url = $(this).attr("href"); var code = $(this).children('span').html(); clip.setText( $(this).children('span').html() );//this.innerHTML ); clip.glue(this); clip.addEventListener('onMouseDown', function(){ clip.reposition(this); clip.setText( code ); }); clip.addEventListener('onComplete', function(){ clip.reposition(this); popUp(url); }); }); }); function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=1024,height=768,left = 328,top = 141');"); } 

我成功生成了复制到剪贴板function,但是如果我使用onMouseUp,onComplete事件来触发弹出function,它会像4-5弹出窗口一样触发或根本不触发。

PS我试图改进如何使用jQuery和ZeroClipboard将Ajax响应加载到剪贴板中的解决方案? 而不是ajax调用只是复制到剪贴板,并完成午餐弹出…正如我说的那样对我不起作用。

在启用flashblocker时我想出了什么呢?每次翻转CODE标签时,都会在同一位置创建一个新的闪存,这可能就是为什么我点击它时会弹出3-4个弹出窗口的原因。 如果我翻滚更多,会有更多弹出窗口出现。 有没有办法阻止闪存在相同位置创建或在推出时销毁?

经过更多的研究,我得到了解决这个问题的方法:

 $("a.xxx").each(function() { //Create a new clipboard client var clip = new ZeroClipboard.Client(); clip.setHandCursor( true ); //Glue the clipboard client to the last td in each row clip.glue(this); var url = $(this).attr("href"); //Grab the text from the parent row of the icon var code = $(this).children('span').html(); clip.setText(code); //Add a complete event to let the user know the text was copied clip.addEventListener('complete', function(client, text) { //alert("Copied text to clipboard:\n" + text); popUp(url); }); }); 

如果其他人都会遇到这个问题,这就是解决方案。

尝试使用http://www.steamdev.com/zclip/它允许您直接访问jquery,您可以在return语句中使用自己的逻辑。

包括jquery.zclip.js下载并保存ZeroClipboard.swf

这是一个片段:

 $(".class-to-copy").zclip({ path: "assets/js/ZeroClipboard.swf", copy: function(){ return $(this).attr("data-attribute-with-text-to-copy"); } }); 

确保更改swf的路径。

Andrei C回答的是过时的。 就这样做吧。

 111 111 111