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. mysql按照时间热度排序2. android-studio - android app微信登录一定要申请了登录权限才能测试?3. 网页爬虫 - python爬虫用BeautifulSoup爬取<s>元素并写入字典,但某些div下没有这一元素,导致自动写入下一条,如何解决?4. 导入数据库不成功5. python3.x - python多进程,不能在同一窗口吗6. javascript - chart.js如何修改某个指定bar的颜色7. 使用weex扩展html5的项目存在ios不同版本的兼容性8. sublime-text - sublime text 3中编译python(sublimeREPL),如何仅运行单行/选定部分9. pdo_mysql 值自增写法10. javascript - html5多个label中其中一个触发change,如何判断是哪一个出发了change

网公网安备