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