javascript 以编程方式发送悬停事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6222724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
send hover event programmatically
提问by Elgoog
Just a quick question about hover events, How can I send a hover event to an element without the user hovering (programmatically).
只是一个关于悬停事件的快速问题,如何在没有用户悬停(以编程方式)的情况下向元素发送悬停事件。
example:
例子:
// Send hover event
$('#myDiv').sendHoverEvent();
// What to do once hovering
$('#myDiv').hover(console.log('hovering'));
回答by Andrew Cooper
Try this:
试试这个:
$('#myDiv').trigger('mouseenter');
回答by natedavisolds
Hover connects two events. The one you want to trigger is mouseenter.
悬停连接两个事件。您要触发的是 mouseenter。
$('#myDiv').mouseenter();
回答by Daniel Kmak
For testing Bootstrap tooltips showing it's better to use:
为了测试 Bootstrap 工具提示,最好使用:
$('#myDiv').mouseenter();
trigger('hover')
simply isn't sufficient to trigger it.
trigger('hover')
根本不足以触发它。