Table of Contents
1 Introducing the plug-in
2 Basic usage
3 Others Description
4 Advanced usage
Home Web Front-end JS Tutorial Share the basic usage of clipboard.js

Share the basic usage of clipboard.js

Mar 07, 2018 pm 04:13 PM
javascript Instructions

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