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

摘要:

  最近项目上要实现一个点击按钮复制连接的功能,刚开始查找了一些资料,找了几款插件,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() {

    }
});