Home >Web Front-end >JS Tutorial >Implementation of jquery one-click copy to clipboard function
This article mainly brings you an example of jquery copying to the clipboard with one click. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.
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.
<a id="copy" data-text="123456">复制文本</a> $(function(){ var clipboard = new Clipboard('#copy',{ text: function(trigger) { alert("复制成功!"); return trigger.getAttribute('data-text'); } }); });
Related recommendations:
How to use jquery to copy to the clipboard with one click
JavaScript code sharing for how to use ZeroClipboard to operate the clipboard
How to get html based on the specified clipboard?
The above is the detailed content of Implementation of jquery one-click copy to clipboard function. For more information, please follow other related articles on the PHP Chinese website!