JavaScript Reference/Event Handlers Reference/onKeyPress

Материал из Web эксперт
Перейти к: навигация, поиск

"onKeyPress" Example

   <source lang="javascript">
   

<html> <head> <script language="JavaScript"> function function1() {

   msg = "on" + event.type + " event fired by " + """ + event.srcElement.id + """; 
   alert(msg) 

} </script></head> <body id="myBody" onkeypress="function1()">

Press any key to fire the event

</body> </html>


     </source>
   
  


"onKeyPress" is applied to

   <source lang="javascript">

+----------------+--------------------------------------------------------------+ | Applied_To |<a> <acronym> | | |<address> <applet> | | |<area> | | | |

| |
<body> |

| |<button> |

| |
|

| | <custom> | | |

| | | <dir> |

| |
|

| |document

| | | <fieldset> | | | <form> |

| |<hn>
|

| | <input type="button"> | | |<input type="checkbox"> <input type="file"> | | |<input type="image"> <input type="password"> | | |<input type="radio"> <inputtype="reset"> | | |<input type="submit"> <input type="text"> | | | | | |<label> <legend> |

| |
  • <listing> | | |<map> <marquee> | | |<menu> <nobr> | | |<noframes> <noscript> | | |<object>
      | | |<optgroup> <option> | | |

                               |
      |                |                                                       |
      |                |                                                     |
      |                |                          <select>                      |
      |                |                                                 |
      |                |                                              |
      |                |                                                    |
      |                |                         <tbody>                       |
      |                |                          |
      |                |                                                       |
      |                |
        | | |<xmp> | +----------------+--------------------------------------------------------------+ </source>

        "onKeyPress" Properties

        <source lang="javascript"> +----------------+--------------------------------------------------------------+ | Properties |altKey altLeft | | |cancelBubble clientX | | |clientY ctrlKey | | |ctrlLeft keyCode | | |offsetX offsetY | | |returnValue screenX | | |screenY shiftKey | | |shiftLeft srcElement | | |type x | | |y | +----------------+--------------------------------------------------------------+

        </source>



        "onKeyPress" Syntax and Note

        <source lang="javascript"> Note:

        This event fires when the user presses any key on the keyboard.

        </source>

      <textarea> | | |<tfoot> | | |<thead>