Home >Web Front-end >JS Tutorial >Copy text to clipboard with one click using jquery

Copy text to clipboard with one click using jquery

一个新手
一个新手Original
2017-09-20 10:06:324650browse

There is a function in my project today. You can copy a piece of text to the clipboard by clicking a button. I found some on the Internet and sorted it out for the convenience of friends who need it.

<a id="copy" data-clipboard-text="123456">复制文本</a>
$(function(){
var clipboard = new Clipboard(&#39;#copy&#39;,{         
text: function(trigger) { alert("复制成功!");           
return trigger.getAttribute(&#39;data-clipboard-text&#39;);        
}   
});
});

The above is the detailed content of Copy text to clipboard with one click using jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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