jquery 触发器悬停在锚点上 [英] jquery trigger hover on anchor
问题描述
我正在使用 jQuery 在网络环境中进行开发.
I'm using jQuery to develop in web environment.
我想知道为什么
$("#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
是锚点的名称,#pop-up
是我网页中的一个 div 元素.
a#trigger
is the name of the anchor, and #pop-up
is a div element in my web.
问题是我想将鼠标悬停在 FullCalendar 插件中的某个事件上,但这些功能不起作用.谢谢.
The problem is that I want to mouse over some event in FullCalendar plugin and those functions aren't working. Thanks.
推荐答案
你走对了,问题是选择器中多了一个#
,去掉第一个hash即可:
You are on the right track, the problem is the extra #
in the selector, just remove the first hash:
$("a#trigger").trigger('mouseenter');
注意,由于ID必须是唯一的,所以不需要指定元素类型,$('#trigger')
效率更高.
Note that since IDs must be unique, there is no need to specify the element type, $('#trigger')
is more efficient.
还要注意:
在 jQuery 1.8 中弃用,在 1.9 中删除: 名称 "hover"
用作字符串 "mouseenter mouseleave"
的简写.它为这两个事件附加了一个事件处理程序,处理程序必须检查 event.type
以确定事件是 mouseenter
还是 mouseleave
.不要将 "hover"
伪事件名称与接受一两个函数的 .hover()
方法混淆.
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 触发器悬停在锚点上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!