constructor-selector.html 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>constructor-selector</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" data-clipboard-text="1">Copy</button>
  11. <button class="btn" data-clipboard-text="2">Copy</button>
  12. <button class="btn" data-clipboard-text="3">Copy</button>
  13. <!-- 2. Include library -->
  14. <script src="../dist/clipboard.min.js"></script>
  15. <!-- 3. Instantiate clipboard by passing a string selector -->
  16. <script>
  17. var clipboard = new ClipboardJS('.btn');
  18. clipboard.on('success', function (e) {
  19. console.info('Action:', e.action);
  20. console.info('Text:', e.text);
  21. console.info('Trigger:', e.trigger);
  22. });
  23. clipboard.on('error', function (e) {
  24. console.info('Action:', e.action);
  25. console.info('Text:', e.text);
  26. console.info('Trigger:', e.trigger);
  27. });
  28. </script>
  29. </body>
  30. </html>