這篇文章主要介紹了JS實現(xiàn)剪切、復制、粘貼——clipBoard.js 的相關(guān)資料,需要的朋友可以參考下
摘要:
最近做了一個項目,其中有這樣一需求:實現(xiàn)一個點擊按鈕復制鏈接的功能,通過網(wǎng)上找相關(guān)資料,找到了幾個插件,ZeroClipboard是通過flash實現(xiàn)的復制功能,隨著越來越多的提議廢除flash,于是就想能不能通過js來實現(xiàn)復制剪切呢?
地址: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() {
}
});