這里不是已經(jīng)組織冒泡了嗎,為什么點(diǎn)擊span顯示的是內(nèi)層和外層
//為 Id 為 content 的 <div> 元素綁定 click 事件 ?
? ? $("#content").click(function(event) {
? ? ? ? $("#msg").html($("#msg").html() + "<p>外層div元素被單擊</p>");
? ? ? ? event.stopPropagation(); //阻止事件冒泡 ?
? ? });
//為 Id 為 content 的 <div> 元素綁定 click 事件 ?
? ? $("#content").click(function(event) {
? ? ? ? $("#msg").html($("#msg").html() + "<p>外層div元素被單擊</p>");
? ? ? ? event.stopPropagation(); //阻止事件冒泡 ?
? ? });
2017-02-17
舉報
2017-02-17
阻止的應(yīng)該是他往上層body的冒泡,而不是span往content的冒泡。你把event.stopPropagation(); 加到span的點(diǎn)擊事件里就可以觀察了,我是這樣理解的。