mouserover和mouseenter事件和冒泡事件
鼠标自上划到下, mouseover次数:1, mouseover冒泡次数:6; mouseenter次数:2, mouseenter冒泡次数: 7
鼠标单独移入.mouseenter()方法块, mouseenter次数:1, mouseenter冒泡次数:1
提问:
1. i, n在两个<script>中不是都初始为零了? 为什么会叠加?
2. mouseenter和mouserover的冒泡事件和事件的区别就是function括号里面是否有e?
3. mouseenter的冒泡事件和事件的效果相同?
4. mouseover的冒泡事件相当于自己就能够实现移入和移出?
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title></title> <style> .left div, .right div { width: 350px; height: 150px; padding: 5px; margin: 5px; border: 1px solid #ccc; } p{ height: 50px; border: 1px solid red; margin: 30px; } .left div { background: #bbffaa; } .right div { background: yellow; } </style> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> </head> <body> <h2>.mouseover()方法</h2> <div class="left"> <div class="aaron1"> <p>鼠标离开此区域触发mouseover事件</p> <a>mouseover事件触发次数:</a><br/> <a>mouseover冒泡事件触发次数:</a> </div> </div> <h2>.mouseenter()方法</h2> <div class="right"> <div class="aaron2"> <p>鼠标进入此区域触发mouseenter事件</p> <a>mouseenter事件触发次数:</a><br/> <a>mouseenter冒泡事件触发次数:</a> </div> </div> <br/> <script type="text/javascript"> var i = 0; $(".aaron1 p").mouseover(function(e) { $(".aaron1 a:first").html('mouseover事件触发次数:' + (++i)) }) var n = 0; $(".aaron1").mouseover(function() { $(".aaron1 a:last").html('mouseover冒泡事件触发次数:' + (++n)) }) </script> <script type="text/javascript"> var i = 0; $(".aaron2 p").mouseenter(function(e) { $(".aaron2 a:first").html('mouseenter事件触发次数:' + (++i)) }) var n = 0; $(".aaron2").mouseenter(function() { $(".aaron2 a:last").html('mouseenter冒泡事件触发次数:' + (++n)) }) </script> </body> </html>