function-target.html 975 B

12345678910111213141516171819202122232425262728293031323334353637
  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.info('Action:', e.action);
  23. console.info('Text:', e.text);
  24. console.info('Trigger:', e.trigger);
  25. });
  26. clipboard.on('error', function (e) {
  27. console.info('Action:', e.action);
  28. console.info('Text:', e.text);
  29. console.info('Trigger:', e.trigger);
  30. });
  31. </script>
  32. </body>
  33. </html>