Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to share with you how JavaScript+Html5 button to copy text to the clipboard function of the relevant knowledge points, detailed content, clear logic, I believe that most people are too aware of this knowledge, so share this article for your reference, I hope you have something to gain after reading this article, let's take a look at it.

The following is a record of how it is used:

One: introduce plug-ins:

Second, add an attribute to the tag: data-clipboard-text

Copy

Third, define script: implement copy function-(write internal script, external ones always report errors, can't find classes, novices don't understand it, I'll add it later)

Var clipboard = new Clipboard ('btn'); clipboard.on (' success', function (e) {e.clearSelection (); / / replication successful}); clipboard.on ('error', function (e) {/ / replication failed})

Add: new Clipboard ()-any parameter is id class, like id or .class as defined by css

Four: customize the copied content

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

Return the content you want to copy through return

Five: the list page copies each piece of list content

You can give each item custom attribute data-clipboard-text.

Div.setAttribute ("data-clipboard-text", "asdf")

Add: almost all computer browsers can support Android on mobile phones. Apple has some problems and needs to set the tag to button.

Thank you for reading! About "JavaScript+Html5 how to achieve button copy text to clipboard function" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

These are all the contents of the article "how to copy text to the clipboard by JavaScript+Html5 button". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report