javascript - select事件不冒泡解释
问题描述
想请问下,select事件不会发生冒泡
当我的鼠标点击下拉框的时候为何会控制台出现 s1 d3 d2 d1
当我点击下拉框中的数字时 又会出现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:你这不是点击事件触发产生的冒泡? 触发了两次是因为你打开下拉框一次,收起下拉框一次
回答2:首先,select事件会冒泡,但你的代码和select事件没啥关系,select事件其次,你控制台的输出是因为触发click事件冒泡产生的
相关文章:
1. docker内创建jenkins访问另一个容器下的服务器问题2. javascript eval3. Docker for Mac 创建的dnsmasq容器连不上/不工作的问题4. 关于docker下的nginx压力测试5. docker镜像push报错6. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?7. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””8. docker 17.03 怎么配置 registry mirror ?9. 使用C#如何导入导出Excel文件?10. android-studio - android studio 结巴了,有什么办法可以治好它吗?