index.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>test</title>
  6. </head>
  7. <body>
  8. <input type="text" id="data" value="剪切板">
  9. <button id="copy">复制</button>
  10. <button id="cut">剪切</button>
  11. <!--[if IE]>
  12. <button id="paste">粘贴</button>
  13. <![endif]-->
  14. <script src="../clipBoard.min.js"></script>
  15. <script>
  16. /**
  17. * 复制、剪切:chrome、Firefox、ie
  18. * 粘贴:ie
  19. * @date 2016-04-25
  20. * @return {[type]} [description]
  21. */
  22. document.getElementById('copy').onclick = function() {
  23. var test = new clipBoard(document.getElementById('data'), {
  24. beforeCopy: function() {
  25. alert('开始复制');
  26. },
  27. copy: function() {
  28. return document.getElementById('data').value;
  29. },
  30. afterCopy: function() {
  31. alert('复制成功!');
  32. }
  33. });
  34. };
  35. document.getElementById('cut').onclick = function() {
  36. var test = new clipBoard(document.getElementById('data'), {});
  37. test.cut();
  38. };
  39. document.getElementById('paste').onclick = function() {
  40. var a = new clipBoard(document.getElementById('data'), {});
  41. a.paste();
  42. };
  43. </script>
  44. </body>
  45. </html>