js_test.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>JS elements test</title>
  5. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
  6. <style>
  7. #draggable {
  8. width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0;
  9. background:#ccc;
  10. opacity:0.5;
  11. }
  12. #droppable {
  13. width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px;
  14. background:#eee;
  15. }
  16. #waitable {
  17. width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px;
  18. background:#eee;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div class="elements">
  24. <div id="clicker">not clicked</div>
  25. <div id="mouseover-detector">no mouse action detected</div>
  26. <div id="invisible" style="display: none">invisible man</div>
  27. <input id="focus-blur-detector" type="text" value="no action detected"/>
  28. <input class="input first" type="text" value="" />
  29. <input class="input second" type="text" value="" />
  30. <input class="input third" type="text" value="" />
  31. <div class="text-event"></div>
  32. </div>
  33. <div id="draggable" class="ui-widget-content"></div>
  34. <div id="droppable" class="ui-widget-header">
  35. <p>Drop here</p>
  36. </div>
  37. <div id="waitable"></div>
  38. <script src="js/jquery-1.6.2-min.js"></script>
  39. <script src="js/jquery-ui-1.8.14.custom.min.js"></script>
  40. <script>
  41. $(document).ready(function() {
  42. var $clicker = $('#clicker');
  43. $clicker.click(function() {
  44. $(this).text('single clicked');
  45. });
  46. $clicker.dblclick(function() {
  47. $(this).text('double clicked');
  48. });
  49. $clicker.bind('contextmenu', function() {
  50. $(this).text('right clicked');
  51. });
  52. var $focusDetector = $('#focus-blur-detector');
  53. $focusDetector.focus(function() {
  54. $(this).val('focused');
  55. });
  56. $focusDetector.blur(function() {
  57. $(this).val('blured');
  58. });
  59. $('#mouseover-detector').mouseover(function() {
  60. $(this).text('mouse overed');
  61. });
  62. $('.elements input.input.first').keydown(function(ev) {
  63. $('.text-event').text('key downed:' + ev.altKey * 1 + ' / ' + ev.ctrlKey * 1 + ' / ' + ev.shiftKey * 1 + ' / ' + ev.metaKey * 1);
  64. });
  65. $('.elements input.input.second').keypress(function(ev) {
  66. $('.text-event').text('key pressed:' + ev.which + ' / ' + ev.altKey * 1 + ' / ' + ev.ctrlKey * 1 + ' / ' + ev.shiftKey * 1 + ' / ' + ev.metaKey * 1);
  67. });
  68. $('.elements input.input.third').keyup(function(ev) {
  69. $('.text-event').text('key upped:' + ev.which + ' / ' + ev.altKey * 1 + ' / ' + ev.ctrlKey * 1 + ' / ' + ev.shiftKey * 1 + ' / ' + ev.metaKey * 1);
  70. });
  71. $( "#draggable" ).draggable();
  72. $( "#droppable" ).droppable({
  73. drop: function( event, ui ) {
  74. $( this ).find( "p" ).html( "Dropped!" );
  75. }
  76. });
  77. var t1, t2;
  78. $('#waitable').click(function() {
  79. var el = $(this);
  80. el.html('');
  81. clearTimeout(t1);
  82. clearTimeout(t2);
  83. t1 = setTimeout(function() {
  84. el.html('<div>arrived</div>');
  85. }, 1000);
  86. t2 = setTimeout(function() {
  87. el.html('<div>timeout</div>');
  88. }, 2000);
  89. });
  90. });
  91. </script>
  92. </body>
  93. </html>