javascript - select事件不冒泡解釋
問題描述

想請問下,select事件不會發(fā)生冒泡
當(dāng)我的鼠標(biāo)點擊下拉框的時候為何會控制臺出現(xiàn) s1 d3 d2 d1
當(dāng)我點擊下拉框中的數(shù)字時 又會出現(xiàn)s1 d3 d2 d1
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Document</title></head><body><p style = 'width:200px;height:200px;background-color:orange;'> <p style = 'width:175px;height:175px;background-color:yellow;'><p style = 'width:150px;height:150px;background-color:blue'> <select id='s1'> <option>1</option> <option>2</option> </select></p> </p></p></p> <script type='text/javascript'>function fun1(){console.log(event.currentTarget.id); }s1.addEventListener('click',fun1,false);d1.addEventListener('click',fun1,false);d2.addEventListener('click',fun1,false);d3.addEventListener('click',fun1,false); </script></body></html>
問題解答
回答1:你這不是點擊事件觸發(fā)產(chǎn)生的冒泡? 觸發(fā)了兩次是因為你打開下拉框一次,收起下拉框一次
回答2:首先,select事件會冒泡,但你的代碼和select事件沒啥關(guān)系,select事件其次,你控制臺的輸出是因為觸發(fā)click事件冒泡產(chǎn)生的
相關(guān)文章:
1. javascript - sublime快鍵鍵問題2. javascript - immutable配合react提升性能?3. css - 寫頁面遇到個布局問題,求大佬們幫解答,在線等,急!~4. javascript - nodejs關(guān)于進(jìn)程間發(fā)送句柄的一點疑問5. Apache 已經(jīng)把網(wǎng)站根目錄的改為allow from all了,但是服務(wù)器還是不能訪問?6. 實現(xiàn)bing搜索工具urlAPI提交7. 配置Apache時,添加對PHP的支持時語法錯誤8. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽數(shù)據(jù)變化9. javascript - 移動端上不能實現(xiàn)拖拽布局嗎?10. phpstudy8.1支持win11系統(tǒng)嗎?

網(wǎng)公網(wǎng)安備