标签:rop tde ati def att null value UNC return
1.绑定
function(element, type, handler){
if (element.addEventListener) {
element.addEventListener(type, handler, false);
}
else
if (element.attachEvent) {
element.attachEvent("on" + type, handler);
}
else {
element["on" + type] = handler;
}
}
2.删除
function(element, type, handler){
if (element.removeEventListener) {
element.removeEventListener(type, handler, false);
}
else
if (element.detachEvent) {
element.detachEvent("on" + type, handler);
}
else {
element["on" + type] = null;
}
}
3.阻止默认事件
function(event){
if (event.preventDefault) {
event.preventDefault();
}
else {
event.returnValue = false;
}
}
4.不传播事件(阻止冒泡)
function(event){
if (event.stopPropagation) {
event.stopPropagation();
}
else {
event.cancelBubble = true;
}
}
5.获得event的target
function(event){
return event.target || event.srcElement;
}
标签:rop tde ati def att null value UNC return
原文地址:https://www.cnblogs.com/justSmile2/p/9623416.html