2009年9月16日 星期三

Cancel event bubbling 取消氣泡事件

參考連結:http://www.quirksmode.org/js/events_order.html
##CONTINUE##
In the Microsoft model you must set the event’s cancelBubble property to true.

window.event.cancelBubble = true


In the W3C model you must call the event’s stopPropagation() method.

e.stopPropagation()


This stops all propagation of the event in the bubbling phase. Stopping event propagation in the capturing phase is impossible. One wonders why.

For a complete cross-browser experience do

function doSomething(e)
{
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
}

2 則留言:

  1. 噗 氣泡事件這翻譯詞實在是很有趣

    我比較喜歡翻成連鎖事件

    回覆刪除
  2. 哈哈,我只是跟著用而已XD

    回覆刪除