JS --- DOM --- an element unbind event

Unbind events:

1, unbundling event

Target = .on event name event handlers --- "binding events.

Object .on event name = null.

Note: binding events in what way, you should unbind event with a corresponding manner.

// 1 = Object .on event name event handler ---- bind events 
    My $ ( "btn") onclick =. Function () { 
      console.log ( "I can do it!" ); 
    }; 
    My $ ( "btn2") the onclick =. function () {
       // 1. unbundling event 
      My $ ( "BTN") the onclick =. null ; 
    };

2, unbundling event

Object .addEventListener ( 'not on the type of event', named function , false); --- binding events

Object .removeEventListener ( 'not on the event type', named function, false);

// click of a button to the second button click event unbound first 
    function F1 () { 
      the console.log ( "1st" ); 
    } 

    function F2 () { 
      the console.log ( "2nd " ); 
    } 
    My $ ( " btn the Click ", f1,") the addEventListener (. " false ); 
    My $ ( " btn the Click ", F2,") the addEventListener (. " false ); 


    // when the unbundling of events, binding events required when using a named function 
    My $ ( "btn2") the onclick =. function () { 
      My $ ( "BTN") the removeEventListener ( "the Click", F1,. to false ); 
    };

r

Guess you like

Origin www.cnblogs.com/ZXH-null/p/12024470.html
Recommended