JS基于clipBoard.js插件實(shí)現(xiàn)剪切、復(fù)制、粘貼

字號(hào):


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