Home  >  Article  >  Web Front-end  >  JS implements cut, copy and paste based on clipBoard.js plug-in_javascript skills

JS implements cut, copy and paste based on clipBoard.js plug-in_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:02:491328browse

Summary:

I recently worked on a project, in which there was such a requirement: to implement a function of clicking a button to copy a link. I searched for relevant information on the Internet and found several plug-ins. ZeroClipboard is a copy function implemented through flash. As more and more people Many people proposed to abolish flash, so I wondered if copying and cutting could be achieved through js?

Address: https://github.com/baixuexiyang/clipBoard.js

Method:

Copy

var copy = new clipBoard(document.getElementById('data'), {
beforeCopy: function() {
},
copy: function() {
return document.getElementById('data').value;
},
afterCopy: function() {
}
}); 

Cut

var cut = new clipBoard(document.getElementById('data'), {
beforeCut: function() {
},
Cut: function() {
return document.getElementById('data').value;
},
afterCut: function() {
}
});

Paste

var paste = new clipBoard(document.getElementById('data'), {
beforePaste: function() {
},
paste: function() {
return document.getElementById('data').value;
},
afterPaste: function() {
}
});

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn