JS實現阻止冒泡事件

function stopBubble(e){
//一般用在鼠標或鍵盤事件上
if(e && e.stopPropagation){
//W3C取消冒泡事件
e.stopPropagation();
}else{
//IE取消冒泡事件
window.event.cancelBubble = true;
}
};

然後在button的click 響應函數的末尾加上

var e = window.event || arguments.callee.caller.arguments[0];
stopBubble(e);
來阻止冒泡事件
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章