JavaScript Reference/Javascript Methods/attachEvent

Материал из Web эксперт
Версия от 11:22, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

"attachEvent()" Example

   <source lang="javascript">
   

<html> <body> <button id="myButton">Button</button> <button onclick="function3();">Apply an event handler "Button"</button> <button onclick="function2();">Detach</button> <script language="JavaScript">

   function function3() {
       document.all.myButton.attachEvent("onclick", function1)
   }
   function function1() {
       document.bgColor = "red";
   }
   function function2() {
       document.bgColor = "white"; 
       document.all.myButton.detachEvent("onclick", function1);
   }

</script> </body> </html>


     </source>
   
  


"attachEvent()" is applied to

   <source lang="javascript">

+----------------+--------------------------------------------------------------+ | Applied_To |<a> <acronym> | | |<address> <applet> | | |<area> | | |<base> <basefont> | | |<bgsound> |

| |
<body> |

| |
<button> |

| |
|

| | | | |<col> <colgroup> | | |<comment> <custom> | | |

| | | <dir> |

| |
|

| |document

| | | <embed> | | |<fieldset> | | |<form> <frame> | | |<frameset> <head> |

| |<hn>
|

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

| |
  • <link> | | |<listing> <map> | | |<marquee> <menu> | | |namespace <nobr> | | |<object>
      | | |<option>

      | | |<plaintext>

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

        "attachEvent()" Syntax, Parameters and Note

        <source lang="javascript"> Note: Bound event to a function in the page. Returns true (successful) or false (failed).

        Syntax:

        window.attachEvent(param1, param2) document.all.elementID.attachEvent(param1, param2) Parameters: param1 Required; the name of the event. param2 Required; the name of the function.


        </source>

      |

      | |<textarea> <tfoot> |

      | |
      <thead> | | |<title>