ZeroClipboard-在复制之前添加到值

ZeroClipboard - Add to values before copying

本文关键字:添加 复制 ZeroClipboard-      更新时间:2023-09-26

我使用的是ZeroClipboard的JS版本。

当用户单击复制按钮时,我想从数据剪贴板文本中捕获数据向其中添加一些额外的数据,然后将其复制到剪贴板。

这是我目前正在使用的代码,在将文本复制到剪贴板之前,我如何添加到文本中?

var clip = new ZeroClipboard( $("input[type='button']"), {
  moviePath: "clip/ZeroClipboard.swf"
});
clip.on( 'complete', function(client, args) {
    alert ('Copied');
});

我以前尝试过使用clip.on,但失败了:

clip.on('dataRequested', function (client, args) {
        clip.setText(args + "NEW VALUE");
    } );

有什么想法吗?

感谢

可以使用"复制"事件处理程序[v2.x]:来设置剪贴板文本

clip.on( "copy", function (event) {
    var clipboard = event.clipboardData;
    clipboard.setData( "text/plain", event.target.innerHTML + " <-- added this text!" );
    /*
     * for data-attribute use event.target.getAttribute("data-clipboard-text")
     */
});
  • http://jsbin.com/zumaluzoxo/edit?html,css,js
  • http://output.jsbin.com/zumaluzoxo/

对于使用"dataRequested"事件处理程序的早期版本[1.x]:

client.on( 'dataRequested', function (client, args) {
  client.setText( this.getAttribute("data-clipboard-text") + "<- Copied me!" );
  /*
   * for text inside component use this.innerHTML
   */
});