The Unbind event in JS

Source: Internet
Author: User

Unbind event:
/*
* Note: In what way to bind the event, you should use the corresponding way to unbind the event
* 1. Unbind Event
* object. On Event name = event handler function---> Bind event
* object. On event name =null;
* 2. Unbind Event
* Object. AddEventListener ("Event type not on", named function, FALSE);---binding event
* Object. RemoveEventListener ("No event type on", function name, false);
* 3. Unbind Event
* Object. Attachevent ("On event type", named function);---binding event
* Object. DetachEvent ("On event Type", function name);
*
*
* */

Page
<! DOCTYPE html>

 

binding and reconciling compatibility codes
<! DOCTYPE html>

  

The first way is common.
my$ ("Btn"). Onclick=function () {console.log ("AA");} my$ ("Btn"). Onclick=null;

  

The second way is common (Firefox Google)
/The second way to support Google and Firefox, does not support IE8  function F1 () {    console.log ("first");  }  function F2 () {    Console.log ("second");  }  my$ ("Btn"). AddEventListener ("click", F1,false);  my$ ("Btn"). AddEventListener ("click", F2,false);  Click the second button to unbind my$ ("Btn2") from the first click event of the first button  . Onclick=function () {    //Unbind event, need to use named function my$ when binding event    ("BTN") . RemoveEventListener ("click", F1,false);  };

  

The Third Way is common (IE8)
The third type supports IE8    function F3 () {    console.log ("first");  }  function F4 () {    Console.log ("second");  }  my$ ("Btn"). Attachevent ("onclick", F3);  my$ ("Btn"). Attachevent ("onclick", F4);  my$ ("Btn2"). Onclick=function () {      my$ ("btn"). DetachEvent ("onclick", F3);  };

  

 

The Unbind event in JS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.