<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jQuery/Js复制文本到剪贴板</title> <script src="http://apps.bdimg.com/libs/jquery/1.8.3/jquery.js"></script> <script type="text/javascript" src="http://www.jq22.com/demo/clipboard.js-master201703170013/dist/clipboard.min.js"></script> </head> <body> <div id="demo">http://www.baidu.com</div> <button class="btn">复制</button> <script> var content = $("#demo").html(); var clipboard = new Clipboard(‘.btn‘, { text: function() { return content; } }); clipboard.on(‘success‘, function(e) { alert("复制成功"); }); clipboard.on(‘error‘, function(e) { console.log(e); }); </script> </body> </html>
来自微信公众号:编程社
程序员日常进阶宝典,欢迎关注!
原文地址:https://www.cnblogs.com/ai10999/p/11449513.html
时间: 2024-10-29 13:43:43