Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use JavaScript+Html5 to realize the function of button copying text to clipboard

Shulou Source: shulou.com Published: 2022-05-31 11:44:51 09月23日 Update

This article is a detailed introduction to "how to use JavaScript+Html5 to realize the function of button copying text to clipboard". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "how to use JavaScript+Html5 to realize the function of button copying text to clipboard" can help you solve your doubts. The following is followed by the idea of Xiaobian. Slowly deepen, learn new knowledge together.

1. Introduction of plug-ins:

Two: Add attributes to tags: data-clipboard-text

Copy

III: Definition script: realize copy function

var clipboard = new Keyboard ('btn ');clipboard.on ('success', function(e) {e.clearSelection();//copy succeeded});clipboard.on ('error ', function(e) {//copy failed});

Supplement: new Keyboard ()----Parameter id class can be the same as css definition id or.class

IV: Custom copy content;

new Clipboard('.btn', { target: function(trigger) { return trigger.nextElementSibling; }});

Return the content you want to copy via return

Five: List Pages Copy the contents of each list

You can customize the attributes data-clipboard-text for each item

div.setAttribute("data-clipboard-text","asdf");

Supplement: almost all computer browsers can support, Android on mobile phones can, Apple has a problem, need to set the label to button

Read here, this article "How to use JavaScript+Html5 to achieve button copy text to the clipboard function" article has been introduced, want to master the knowledge of this article also need to practice to understand, if you want to know more about the content of the article, welcome to pay attention to the industry information channel.

Tags: Content functions copies buttons text cuts articles attributes tags propriety success parameters ideas mobile phones plug-ins news more steps browsers computers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia OPPO Reno vpn Shulou Information MySQL