手动触发鼠标悬停事件而不允许事件传播 [英] Manually trigger mouseover event without allowing the event to propagate
本文介绍了手动触发鼠标悬停事件而不允许事件传播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用jQuery仅针对特定元素触发鼠标悬停事件,而又不允许事件传播到父控件.
How can I trigger mouseover event using jQuery just for a specific element, without allowing the event to propagate to the parent controls.
我知道如何触发事件:$('selector').trigger('mouseover');
I know how to trigger the event: $('selector').trigger('mouseover');
例如,我在tr
中有一个image
.我为他们两个都有悬停事件处理程序.
我只想为图像手动触发悬停事件.
For example I have an image
inside tr
. I have hover event handlers for both of them.
I want to manually trigger hover-in event just for the image.
有人有主意吗?
推荐答案
我在示例此处找到了答案. 这是解决我的问题的代码:
I found the answer looking in the examples here. Here is the code solving my problem:
var event = jQuery.Event('<event_name>');
event.stopPropagation();
$('<selector>').trigger(event);
这篇关于手动触发鼠标悬停事件而不允许事件传播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文