https://blog-static.cnblogs.com/files/php-qiuwei/clipboard.min.js
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="utf-8"> 5 <script src="//cdn.staticfile.org/jquery/1.12.1/jquery.min.js"></script> 6 <script src="clipboard.min.js"></script> 7 <script src="layer/layer.js"></script> 8 </head> 9 <body> 10 <button class="course-share-btn" data-clipboard-text="fdhajkfd">复制课程推广链接</button> 11 12 <script type="text/javascript"> 13 14 $(function(){ 15 16 17 //分享 18 var event_copy = new Clipboard('.course-share-btn'); 19 console.log(event_copy); 20 event_copy.on('success', function(e) { 21 console.info('Text:', e.text); 22 layer.msg('已复制分享内容到粘贴板。'); 23 e.clearSelection(); 24 }); 25 26 event_copy.on('error', function(e) { 27 layer.msg('复制失败,或许您的浏览器不支持该操作'); 28 }); 29 }); 30 </script> 31 32 </body> 33 </html>