<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> <script src="https://cdn.jsdelivr.net/clipboard.js/1.5.12/clipboard.min.js"></script> <title>复制按钮</title> </head> <body> <p>haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p> <span id="target">我是一段优美的文字</span> <button class="btn" data-clipboard-action="copy" data-clipboard-target="#target" id="copy_btn"> 复制按钮 </button> </body> <script> $(document).ready(function(){ var clipboard = new Clipboard('#copy_btn'); clipboard.on('success', function(e) { alert("复制成功",1500); }); clipboard.on('error', function(e) { alert("复制失败,请手动填写",1500); }); }); </script> </html>
实现点击复制指定区域的内容
最新推荐文章于 2024-08-25 14:19:06 发布