Mainly solved
Browser compatibility, now compatible with IE6 7 8 FF Google (nonsense)
In IE, this points to a problem.
Go directly to the code!
Copy codeThe Code is as follows:
Var bind = function (object, type, fn ){
If (object. attachEvent) {// IE browser
Object. attachEvent ("on" + type, (function (){
Return function (event ){
Window. event. cancelBubble = true; // stop time bubble
Object. attachEvent = [fn. apply (object)]; // ---- Here I want to talk about
}
}) (Object), false );
} Else if (object. addEventListener) {// other browsers
Object. addEventListener (type, function (event ){
Event. stopPropagation (); // stop time bubble
Fn. apply (this)
});
}
}
// The following is a click event for the aaa id.
Bind (document. getElementById ("aaa"), "click", function () {alert ("this is the ID of the button you clicked" + this. id + "this is the bound 1st functions ")});
Bind (document. getElementById ("aaa"), "click", function () {alert ("this is the ID of the button you clicked" + this. id + "this is the bound 2nd functions ")});
The code is simple and does not need to be explained. Use it to know. Haha.