Home > Web Front-end > JS Tutorial > body text

jquery implements one-click code sharing to copy to clipboard

小云云
Release: 2018-02-05 13:43:16
Original
1575 people have browsed it

There is a function in my project today, which is to copy a piece of text to the clipboard through a click event. I found some on the Internet and sorted it out for the convenience of friends who need it. This article mainly brings you an example of jquery copying to the clipboard with one click. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor to take a look, I hope it can help everyone.


<a id="copy" data-text="123456">复制文本</a>
$(function(){
    var clipboard = new Clipboard(&#39;#copy&#39;,{ 

       text: function(trigger) { 

          alert("复制成功!");

          return trigger.getAttribute(&#39;data-text&#39;); 

       }

    });
});
Copy after login

Related recommendations:

How to use jquery to copy to the clipboard with one click

js instance method of copying to the clipboard_javascript skills

JS copy specified content to the clipboard sample code_javascript skills

The above is the detailed content of jquery implements one-click code sharing to copy to clipboard. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!