function-text.html 941 B

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