stopEvent 冒泡与捕获及阻止默认动作

The difference between 'return false;' and 'e.preventDefault();'

参考:http://css-tricks.com/6809-return-false-and-prevent-default/

cabcelable属性表示事件是否可取消,只有此属性为true时,事件对象的preventDefault方法才会起到阻止事件默认行为的作用。

封装函数:

function stopEvent(event){
var e = (event) ? event : window.event;

if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
else {
e.cancelBubble = true;
e.returnValue = false;
}

}



posted @ 2011-10-11 14:28  wkylin  阅读(356)  评论(0编辑  收藏  举报