在JQuery中停止鼠标悬停的传播 [英] Stopping propagation of mouseover in JQuery
本文介绍了在JQuery中停止鼠标悬停的传播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我将鼠标悬停在子元素上时,也会调用父事件.如何停止?
When I hover over a child element, the parent's event is also called. How do I stop it?
<div class="parent">
<div class="child">
</div>
</div>
$(".parent").on("mouseover", function(){//Shouldnt fire on child})
$(".child").on("mouseover", function(){//Child function})
推荐答案
只需在child中捕获事件并停止其传播,如下所示:
Just catch the event in child and stop its propagation as follows:
$(".child").on("mouseover", function(e){
e.stopPropagation();
//Child function})
PS:这里至少有一千个与此类似的问题.请做你的研究.
PS: There are atleast a thousand questions here similar to this. Please do your research.
这篇关于在JQuery中停止鼠标悬停的传播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文