我正在使用jQuery在Web环境中开发.
我想知道为什么
- $("#a#trigger").trigger('mouseenter');
- $("#a#trigger").trigger('hover');
- $("#a#trigger").trigger('mouSEOver');
其中3个都不能激活我拥有的悬停功能.
- $(function() {
- $('a#trigger').hover(function(e) {
- $('div#pop-up').show();
- },function() {
- $('div#pop-up').hide();
- });
- });
- });
#触发器是锚的名称,#弹出是我的网络中的div元素.
解决方法
你在正确的轨道上,问题是选择器中的额外的#,只是删除第一个哈希:
- $("a#trigger").trigger('mouseenter');
请注意,由于ID必须是唯一的,因此不需要指定元素类型,$(‘#trigger’)更有效.
另请注意:
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.