我使用的是 JS 版本的 ZeroClipboard。
当用户单击复制按钮时,我想从 data-clipboard-text 捕获数据,并向其中添加一些额外的数据,然后将其复制到剪贴板。
这是我当前正在使用的代码,如何在将文本复制到剪贴板之前添加到文本中?
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");
} );
有什么想法吗?
谢谢
最佳答案
Setting the clipboard text可以使用“复制”事件处理程序 [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")
*/
});
<小时/>
For previous version [1.x]使用“dataRequested”事件处理程序:
client.on( 'dataRequested', function (client, args) {
client.setText( this.getAttribute("data-clipboard-text") + "<- Copied me!" );
/*
* for text inside component use this.innerHTML
*/
});
关于javascript - ZeroClipboard - 在复制之前添加到值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37330106/