function-target.html 743 B

123456789101112131415161718192021222324252627282930313233
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>function-target</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. </head>
  8. <body>
  9. <!-- 1. Define some markup -->
  10. <button class="btn">Copy</button>
  11. <div>hello</div>
  12. <!-- 2. Include library -->
  13. <script src="../dist/clipboard.min.js"></script>
  14. <!-- 3. Instantiate clipboard -->
  15. <script>
  16. var clipboard = new ClipboardJS('.btn', {
  17. target: function() {
  18. return document.querySelector('div');
  19. }
  20. });
  21. clipboard.on('success', function(e) {
  22. console.log(e);
  23. });
  24. clipboard.on('error', function(e) {
  25. console.log(e);
  26. });
  27. </script>
  28. </body>
  29. </html>