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. html - 爬虫时出现“DNS lookup failed”,打开网页却没问题,这是什么情况?2. css - ul ol前边的标记如何调整样式呢3. 在windows下安装docker Toolbox 启动Docker Quickstart Terminal 失败!4. docker内创建jenkins访问另一个容器下的服务器问题5. dockerfile - [docker build image失败- npm install]6. dockerfile - 为什么docker容器启动不了?7. macos - mac下docker如何设置代理8. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?9. docker api 开发的端口怎么获取?10. docker绑定了nginx端口 外部访问不到

网公网安备