关注用户体验,分享前端技术

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() {

    }
});

 

posted @ 2016-05-03 08:49  夕阳白雪  阅读(2127)  评论(6编辑  收藏  举报