老师,我的问题是关于mouseover,mouseout事件?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <!DOCTYPE html> < html > < head > < meta charset = "UTF-8" > < title >5</ title > < style > .one{ width: 200px; height: 200px; background-color: red; } .two{ width: 100px; height: 100px; background-color: blue; } </ style > </ head > < body > < div class = "one" > < div class = "two" > </ div > </ div > < script type = "text/javascript" src = "js/jquery.js" ></ script > < script > $('.two').mouseover(function(){ console.log('two over'); }) $('.two').mouseout(function(){ console.log('two out'); }) $('.one').mouseover(function(){ console.log('one over'); }) $('.one').mouseout(function(){ console.log('one out'); }) </ script > </ body > </ html > |
老师,结果为什么是one over---one out---two over---one over---two out---one out---one over---one out这样啊?
19
收起
正在回答
1回答
同学你好!
这个效果是正常的,mouseover 和 mouseout 事件是可以冒泡的,子元素上触发的事件会冒泡到父元素上。可以换成中文,来看下效果:
如果帮助到了你,欢迎采纳,祝学习愉快~
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧