//绑定事件
function addEventListener(element, type, fn) {
//火狐 谷歌
if (element.addEventListener) {
element.addEventListener(type, fn, false);
}
//IE
else if (element.attachEvent){
element.attachEvent(‘on’ + type,fn);
}
//正常情况
else {
element[‘on’+type] = fn;
}
}
//解绑事件
function removeEventListener(element, type, fn) {
//火狐 谷歌
if (element.removeEventListener) {
element.removeEventListener(type, fn, false);
}
//IE
else if (element.detachEvent) {
element.detachEvent(‘on’ + type, fn);
}
//正常情况
else {
element[‘on’+type] = null;
}
}