摘要:
最近項目上要實現一個點擊按鈕復制鏈接的功能,剛開始查找了一些資料,找了幾款插件,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() { } });