if(!window.attachEvent && window.addEventListener)
{
Window.prototype.attachEvent = HTMLDocument.prototype.attachEvent=
HTMLElement.prototype.attachEvent=function(en, func, cancelBubble)
{
var cb = cancelBubble ? true : false;
this.addEventListener(en.toLowerCase().substr(2), func, cb);
};
}
那就这段代码好了,是不是浏览器探测来着,window.attachEvent 和window.addEventListener这两个是不是特定浏览器的对象属性.
{
Window.prototype.attachEvent = HTMLDocument.prototype.attachEvent=
HTMLElement.prototype.attachEvent=function(en, func, cancelBubble)
{
var cb = cancelBubble ? true : false;
this.addEventListener(en.toLowerCase().substr(2), func, cb);
};
}
那就这段代码好了,是不是浏览器探测来着,window.attachEvent 和window.addEventListener这两个是不是特定浏览器的对象属性.
Attaches the specified event handler and
function to the element so that every time
the event fires, the function is called.(attachevent IE5.0+)
这莫写就是考虑了浏览器的兼容性