XML DOM bubbles 事件屬性
定義和用法
bubbles 事件屬性返回一個布爾值,如果事件是起泡類型,則返回 true,否則返回 fasle。
語法
event.bubbles
事件傳播
在 2 級 DOM 中,事件傳播分為三個階段:
第一,捕獲階段。事件從 Document 對象沿著文檔樹向下傳遞給目標節(jié)點。如果目標的任何一個先輩專門注冊了捕獲事件句柄,那么在事件傳播過程中運行這些句柄。
第二個階段發(fā)生在目標節(jié)點自身。直接注冊砸目標上的適合的事件句柄將運行。這與 0 級事件模型提供的事件處理方法相似。
第三,起泡階段。在此階段,事件將從目標元素向上傳播回或起泡回 Document 對象的文檔層次。
實例
下面的例子可檢測發(fā)生的事件是否是一個起泡事件:
<html>
<head>
<script type="text/javascript">
function getEventType(event)
{
alert(event.bubbles
);
}
</script>
</head>
<body onmousedown="getEventType(event)">
<p>Click somewhere in the document.
An alert box will tell if the event is a bubbling event.</p>
</body>
</html>
TIY
- bubbling event
- 檢測事件是否是起泡事件(IE 瀏覽器不支持)。