Clipboard official documentation: https://clipboardjs.com/
Installation:
1. Run NPM: NPM install clipboard -- save
2. Download: https://github.com/zenorocha/clipboard.js/archive/master.zip
Usage:
1. Copy content from other components:
<! -- Target --> <input id = "foo" value = "https://github.com/zenorocha/clipboard.js.git"> <! -- Trigger --> <button class = "BTN" data-clipboard-target = "# foo"> </button>
2. Cut other components:
<! -- Target --> <textarea id = "bar"> mussum ipsum cacilds... </textarea> <! -- Trigger --> <button class = "BTN" data-clipboard-action = "cut" data-clipboard-target = "# bar">Cut to clipboard </button>
3. Copy the self-built content:
<! -- Trigger --> <button class = "BTN" data-clipboard-TEXT = "just because you can doesn't mean you shocould-clipboard. js">Copy to clipboard </button>
Event:
VaR clipboard = new clipboardjs ('. BTN'); Clipboard. On ('success', Function(E) {console.info ('Action :', E. Action); lele.info ('text :', E. Text); lele.info ('triggers :', E. Trigger); E. clearselection () ;}); clipboard. On ('error', Function(E) {console. Error ('Action :', E. Action); console. Error ('triggers :', E. Trigger );});
click Copy content to the clipboard