Home > Web Front-end > JS Tutorial > Share the basic usage of clipboard.js

Share the basic usage of clipboard.js

小云云
Release: 2018-03-07 16:13:00
Original
6419 people have browsed it

clipboard.js is a plug-in that copies text to the clipboard without flash. This article mainly introduces you to the basic usage of clipboard.js. I hope it can help you.

1 Introducing the plug-in

<script src="js/clipboard.min.js"></script>
Copy after login

2 Basic usage

First you need to instantiate it by passing a DOM selector, HTML element or HTML element list.

new Clipboard(&#39;.btn&#39;);
Copy after login


1 Use one element as a trigger to copy the text of another element. The data-clipboard-target attribute needs to be followed by the attribute selector

<!-- Target -->
<input id="foo" value="https://github.com/zenorocha/clipboard.js.git">
<!-- Trigger -->
<button class="btn" data-clipboard-target="#foo">
</button>
Copy after login

In addition, there are Another attribute, data-clipboard-action attribute, is used to specify whether copy or cut operation is required. The default is copy. The cut operation only works on or