JavaScript Reference/Javascript Methods/detachEvent

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

"detachEvent()" 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>
   
  


"detachEvent()" 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>

        "detachEvent()" Syntax, Parameters and Note

        <source lang="javascript"> Note: Detach attached event handler function from its event. This is the opposite of the attachEvent() method.

        Syntax:

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


        </source>

      |

      | |<textarea> <tfoot> |

      | |
      <thead> | | |<title>