<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title></title></Head><Body><inputtype= "button"value= "button"ID= "BT"/><inputtype= "button"value= "Unbind event"ID= "BT2"/><Scriptsrc= "Common.js"></Script><Script> //Binding Event-compatible code functionAddeventlistner (element, type, fn) {if(Element.addeventlistener) {Element.addeventlistener (type, FN,false); } Else if(element.attachevent) {element.attachevent (" on" +type, fn); } Else{element[" on" +Type]=fn; } } //compatible code for unbinding events functionRemoveeventlistner (element, type, fnname) {if(Element.removeeventlistener) {Element.removeeventlistener (type, fnname,false); } Else if(element.detachevent) {element.detachevent (" on" +type, fnname); } Else{element[" on" +Type]= NULL; } } //Test functionF1 () {Console.log ("first one"); } functionF2 () {Console.log ("a second"); } addeventlistner (my$ ("BT"), "Click", F1); Addeventlistner (my$ ("BT"), "Click", F2); my$ ("BT2"). onclick= function() {Removeeventlistner (my$ ("BT"), "Click", F1); };</Script></Body></HTML>
Compatible code for JavaScript binding events and Unbinding events