最近項目上要實現一個點擊按鈕複製連接的功能,剛開始查找了一些資料,找了幾款插件,ZeroClipboard是經過flash實現的複製功能,隨着愈來愈多的提議廢除flash,因而就想能不能經過js來實現複製剪切呢?git
地址:https://github.com/baixuexiyang/clipBoard.jsgithub
複製spa
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() { } });
粘貼code
var paste = new clipBoard(document.getElementById('data'), { beforePaste: function() { }, paste: function() { return document.getElementById('data').value; }, afterPaste: function() { } });