JavaScript Reference/Javascript Methods/focus

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

"focus()" Example

   <source lang="javascript">
   

<html> <body> <script language="JavaScript">

   function function1() {
       document.all.myElement.focus();
   }
   function function2() {
       alert("onFocus event has been fired");
   }

</script> <input id="myElement" type="text" value="" onfocus="function2();"> <input type="button"

      value="Give focus to the text input element and fire the event" 
      onclick="function1();">

</body> </html>


     </source>
   
  


"focus()" is applied to

   <source lang="javascript">

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

| |
<body> |

| |<button> |

| |
|

| |<custom>

| | | |

| |<dir>
| | |document
| | | <embed> | | |<fieldset> | | |<form> <frame> | | |<frameset> <hn> | | |
|

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

| |
  • <listing> | | |<marquee> <menu> | | |<object>
      | | |

      <plaintext> | | |

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

        "focus()" Syntax, Parameters and Note

        <source lang="javascript"> Note: Gives focus to an element and fires the onFocus event handler.

        Syntax:

        document.getElementById("elementID").focus() document.all.elementID.focus() // IE only


        </source>

      |

      | |<textarea> <tfoot> |

      | |
      <thead> | | |