jquery 触发器悬停在锚点上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11074815/
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
jquery trigger hover on anchor
提问by Ori Refael
I'm using jQuery to develop in web environment.
我正在使用 jQuery 在 Web 环境中进行开发。
I want to know why
我想知道为什么
$("#a#trigger").trigger('mouseenter');
$("#a#trigger").trigger('hover');
$("#a#trigger").trigger('mouseover');
All 3 of those aren't working to activate a hover function that I have.
所有这三个都无法激活我拥有的悬停功能。
$(function() {
$('a#trigger').hover(function(e) {
$('div#pop-up').show();
}, function() {
$('div#pop-up').hide();
});
});
});
a#trigger
is the name of the anchor, and #pop-up
is a div element in my web.
a#trigger
是锚点的名称,#pop-up
是我网站中的一个 div 元素。
The problem is that I want to mouse over some event in FullCalendar plugin and those functions aren't working. Thanks.
问题是我想将鼠标悬停在 FullCalendar 插件中的某个事件上,但这些功能不起作用。谢谢。
回答by undefined
You are on the right track, the problem is the extra #
in the selector, just remove the first hash:
您在正确的轨道上,问题是#
选择器中的额外内容,只需删除第一个哈希:
$("a#trigger").trigger('mouseenter');
Note that since IDs must be unique, there is no need to specify the element type, $('#trigger')
is more efficient.
请注意,由于 ID 必须唯一,因此无需指定元素类型,$('#trigger')
效率更高。
Also note that:
另请注意:
Deprecated in jQuery 1.8, removed in 1.9:The name
"hover"
used as a shorthand for the string"mouseenter mouseleave"
. It attaches a single event handler for those two events, and the handler must examineevent.type
to determine whether the event ismouseenter
ormouseleave
. Do not confuse the"hover"
pseudo-event-name with the.hover()
method, which accepts one or two functions.
在 jQuery 1.8 中弃用,在 1.9 中删除:
"hover"
用作字符串的简写的名称"mouseenter mouseleave"
。它为这两个事件附加了一个事件处理程序,处理程序必须检查event.type
以确定事件是mouseenter
还是mouseleave
。不要将"hover"
伪事件名称与.hover()
接受一两个函数的方法混淆。
回答by Jonathan Nicol
Your jQuery selector should be written as e.g.
你的 jQuery 选择器应该写成例如
$('a#trigger');
instead of $('#a#trigger');
代替 $('#a#trigger');
In jQuery a # in a selector matches an id. In this case trigger
is an id, but a
is an HTML element and requires no prefix.
在 jQuery 中,选择器中的 # 匹配一个 id。在这种情况下trigger
是一个 id,但它a
是一个 HTML 元素,不需要前缀。
Your final code would be:
您的最终代码将是:
$("a#trigger").trigger('mouseenter');
$("a#trigger").trigger('hover');
$("a#trigger").trigger('mouseover');