操作方法
body部分: <div style="width:200px;height:200px;background:green;"> <p style="width:100px;height:100px;background:red;"></p> </div> <strong></strong>
我们写入移入移出事件demo.js代码: $('div').mouseover(function() { //over会触发子节点 $('strong').html(function (index, value) { return value + '1'; }); }); 你会发现在p里面移入依然会产生1
我们看mouseenter代码: $('div').mouseenter(function() { //enter不会触发子节点 $('strong').html(function (index, value) { return value + '1'; }); }); 你会发现只是在移入div产生1,当你从div移入到p时,没有产生 形象的比喻: mouseover和mouseenter的区别: 类比:mouseenter 就好像电影中xxx国毒品交易一样,你从a国运到xxx国, 你可能只需要过一个安检,你就可以运往xxxx任意地方, 但mouseover就好比xx国毒品交易一样,你从a国运到xx国可能要过a地方的安检,你出来又一次安检, 你再进入其他地方又要过一次安检