Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>keypress demo</title>
  6. <style>
  7. fieldset {
  8. margin-bottom: 1em;
  9. }
  10. input {
  11. display: block;
  12. margin-bottom: .25em;
  13. }
  14. #print-output {
  15. width: 100%;
  16. }
  17. .print-output-line {
  18. white-space: pre;
  19. padding: 5px;
  20. font-family: monaco, monospace;
  21. font-size: .7em;
  22. }
  23. </style>
  24. <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  25. </head>
  26. <body>
  27.  
  28. <form>
  29. <fieldset>
  30. <label for="target">Type Something:</label>
  31. <input id="target" type="text">
  32. </fieldset>
  33. </form>
  34. <button id="other">
  35. Trigger the handler
  36. </button>
  37. <script src="/resources/events.js"></script>
  38.  
  39. <script>
  40. var xTriggered = 0;
  41. $( "#target" ).keypress(function( event ) {
  42. if ( event.which == 13 ) {
  43. event.preventDefault();
  44. }
  45. xTriggered++;
  46. var msg = "Handler for .keypress() called " + xTriggered + " time(s).";
  47. $.print( msg, "html" );
  48. $.print( event );
  49. });
  50.  
  51. $( "#other" ).click(function() {
  52. $( "#target" ).keypress();
  53. });
  54. </script>
  55.  
  56. </body>
  57. </html>
  58.  
  59. $(document).keypress(function(){
  60. alert("I'm pressed");
  61. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement