How do I copy code to the stickboard
Copy code to paste board, used three examples, plain English. And the last example is a little bit of a note
1. If you have a fixed text, div element:
The installation
npm install clipboardjs
Copy the code
html
<div data-clipboard-text=" copy content "> Copy button </div>Copy the code
js
new ClipboardJS('.btn');
Copy the code
2. What if you want to copy a character from another element? Don’t worry. That’s all right
The installation
npm install clipboardjs
Copy the code
html
<input id="foo" value="https://github.com/zenorocha/clipboard.js.git"> <button class="btn" data-clipboard-target="#foo"> <img src="assets/clippy.svg" alt="Copy to clipboard"> </button>Copy the code
js
new ClipboardJS('.btn');
Copy the code
3. What if the copied content is not in HTML at all? Need dynamic Settings?
The important thing to note here is that data-clipboard-text=”1″ must be a placeholder for ~
The installation
npm install clipboardjs
Copy the code
html
<div data-clipboard-text="1" > Copy button </div>Copy the code
js
New ClipboardJS('.copy-btn', {text: ()=>{// return this.webideValue; }});Copy the code
Chinese website: www.clipboardjs.cn/