jQuery的触发器悬停在锚点上 [英] jquery trigger hover on anchor

查看:120
本文介绍了jQuery的触发器悬停在锚点上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想知道为什么

<$ p $ ('mouseenter');

$(#a#trigger)。
$(#a#trigger)。trigger('hover');
$(#a#trigger)。trigger('mouseover');

所有这三个都不能激活我拥有的悬停功能。


$ b $

  $(function(){


$('a#trigger')。hover(function (e){
$('div#pop-up')。show();

},function(){
$('div#pop-up' ).hide();
});

});

});

a#trigger 是锚点和#弹出是我的网络中的div元素。



问题是我想将鼠标悬停在FullCalendar插件中的某个事件上,并且这些功能不起作用。
谢谢。

解决方案

您处于正确的轨道上,问题在于额外的在选择器中,只需删除第一个散列:

  $(a#trigger)。trigger('mouseenter') ; 

请注意,由于ID必须是唯一的,因此不需要指定元素类型 $('#trigger')更高效。

另外请注意:


不推荐使用jQuery 1.8,在1.9中删除:名称hover用作简写字符串mouseenter mouseleave。它为这两个事件附加一个事件处理程序,处理程序必须检查 event.type 来确定事件是否为 mouseenter mouseleave 。不要将hover伪事件名称与 .hover()方法混淆,该方法接受一个或两个功能。



I'm using jQuery to develop in web environment.

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.

The problem is that I want to mouse over some event in FullCalendar plugin and those functions aren't working. Thanks.

解决方案

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.

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 examine event.type to determine whether the event is mouseenter or mouseleave. Do not confuse the "hover" pseudo-event-name with the .hover() method, which accepts one or two functions.

这篇关于jQuery的触发器悬停在锚点上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆