Zeroclipboard multiple elements

半腔热情 提交于 2019-12-04 13:08:26
Andrei C

after more research I got to my solution to this problem:

$("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);
  });
});

this is the solution if anyone else will get stuck on this problem.

Try using http://www.steamdev.com/zclip/ it allows you direct access to jquery and you can use your own logic in the return statement.

include jquery.zclip.js download and save ZeroClipboard.swf

Here is a snippet:

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

Make sure you change the path of the swf.

What Andrei C answered is outdated. Just do it as follows.

<a id="test1" class="test" href="#"  data-clipboard-text="1">111</a>
<a id="test2" class="test" href="#"  data-clipboard-text="2">111</a>
<a id="test3" class="test" href="#"  data-clipboard-text="3">111</a>
<script src="js/jquery-1.11.3.min.js"></script>
<script src="dist1/ZeroClipboard.js"></script>
<script>
var client = new ZeroClipboard( );
client.clip($(".test"));

client.on( "ready", function( readyEvent ) {
  client.on( "aftercopy", function( event ) {
    alert("Copied text to clipboard: " + event.data["text/plain"] );
  } );
});

</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!