js实现剪切、复制、粘贴——clipBoard.js

时间:2023-03-09 00:57:17
js实现剪切、复制、粘贴——clipBoard.js

摘要:

  最近项目上要实现一个点击按钮复制链接的功能,刚开始查找了一些资料,找了几款插件,ZeroClipboard是通过flash实现的复制功能,随着越来越多的提议废除flash,于是就想能不能通过js来实现复制剪切呢?

地址:https://github.com/baixuexiyang/clipBoard.js

方法:

复制

var copy = new clipBoard(document.getElementById('data'), {
beforeCopy: function() { },
copy: function() {
return document.getElementById('data').value;
},
afterCopy: function() { }
});

剪切

var cut = new clipBoard(document.getElementById('data'), {
beforeCut: function() { },
Cut: function() {
return document.getElementById('data').value;
},
afterCut: function() { }
});

粘贴

var paste = new clipBoard(document.getElementById('data'), {
beforePaste: function() { },
paste: function() {
return document.getElementById('data').value;
},
afterPaste: function() { }
});