課程
/前端開發(fā)
/jQuery
/jQuery基礎(chǔ)(三)—事件篇
為啥$("span").click(function() 阻止事件冒泡不成功
2016-07-28
源自:jQuery基礎(chǔ)(三)—事件篇 6-2
正在回答
加上后和注釋后都點(diǎn)下看看就知道了 是成功的
不好意思 看錯(cuò)樓上代碼了,也是可行的
?樓上的試了下并無法阻止冒泡到content
?? $("span").click(function() {??????? $("#msg").html($("#msg").html() + "<p>內(nèi)層span元素被單擊</p>");??? });??? event.stopPropagation();
這樣寫就可以,不太理解
$("span").click(function(e) {
? ? ? ? $("#msg").html($("#msg").html() + "<p>內(nèi)層span元素被單擊</p>");
? ? ? ? e.stopPropagation();
? ? });
這樣寫就可以阻止它冒泡了 要明白冒泡的原因?
使用event.isDefaultPrevented()?
舉報(bào)
jQuery第三階段開啟事件修煉,掌握對(duì)頁(yè)面進(jìn)行交互的操作
2 回答關(guān)于mouseenter和mouseleave阻止冒泡事件
5 回答我不要阻止冒泡
4 回答第一個(gè)click沒有阻止冒泡,那為什么它只冒泡到外層div,沒有冒泡到body
4 回答event.stopPropagation()沒有阻止父級(jí)元素的冒泡事件呢?
2 回答關(guān)于事件冒泡問題,this不事件冒泡,e.target會(huì)事件冒泡???
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-08-11
加上后和注釋后都點(diǎn)下看看就知道了 是成功的
2016-08-03
不好意思 看錯(cuò)樓上代碼了,也是可行的
2016-08-03
?樓上的試了下并無法阻止冒泡到content
?? $("span").click(function() {
??????? $("#msg").html($("#msg").html() + "<p>內(nèi)層span元素被單擊</p>");
??? });
??? event.stopPropagation();
這樣寫就可以,不太理解
2016-07-31
$("span").click(function(e) {
? ? ? ? $("#msg").html($("#msg").html() + "<p>內(nèi)層span元素被單擊</p>");
? ? ? ? e.stopPropagation();
? ? });
這樣寫就可以阻止它冒泡了 要明白冒泡的原因?
2016-07-28
使用event.isDefaultPrevented()?