jQuery AJAY 实时悬停事件?
抱歉,我再次问这个问题,但我找不到解决方案。我知道那里有一些帖子,但对我来说似乎没有任何作用。我正在使用 jquery load() 方法加载网站的一部分。我会将以下规则应用于其中的所有链接:
$('.file a').live('click', function(e) {
alert('click event firde');
});
此单击事件工作得非常好。 但是我也想在这些链接上有一个悬停事件:
$('.file a').live('mouseover mouseout', function(event) {
if (event.type == 'mouseover') {
alert('why doesn't the hover event fire????');
} else {
// do something on mouseout
}
});
我不知道为什么我的悬停事件不会触发?我可以只将一个带有 live 的事件处理程序应用于特定的选择器吗???
有什么想法吗?
sorry i'm asking this again, but I can't find a solution. I know there are a few posts out there, but for me nothing seems to work. I'm loading a part of a website with the jquery load() method. I'll apply the following rule to all links inside them:
$('.file a').live('click', function(e) {
alert('click event firde');
});
this click event works just perfectly fine.
however i want to have a hover event on those links as well:
$('.file a').live('mouseover mouseout', function(event) {
if (event.type == 'mouseover') {
alert('why doesn't the hover event fire????');
} else {
// do something on mouseout
}
});
i have no idea why my hover event wont fire? can i only apply one event handler with live to a specific selector???
any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您想要单独绑定事件,如下所示:
我们使用
mouseenter
和mouseleave
因为这些是.hover()
绑定到。You want to bind the events separately, like this:
We're using
mouseenter
andmouseleave
because these are the events that.hover()
binds to.根据 jQuery 文档,“从 jQuery 1.4.1 .live() 开始,可以接受多个以空格分隔的事件...”。因此,只要您至少使用 v.1.4.1,就应该没问题。我发现的唯一问题是这一行:
这应该是
You had a single quote in a stringliteral by singlequotes 。这将导致该语句及其后的任何语句失败。
讽刺的是,Stack Overflow 的代码着色也在线上失败了。 :)
According to the jQuery documentation, "As of jQuery 1.4.1 .live() can accept multiple, space-separated events...". So as long as you are using at least v. 1.4.1 you should be fine. The only problem I found is this line:
which should be
You had a single quote in a string literal bound by single quotes. That would cause the statement and any after it to fail.
Ironically, Stack Overflow's code coloring fails on the line as well. :)
您确定至少使用 jquery 1.4.1 吗?任何低于该值的代码都将不起作用。
Are you sure you are using at least jquery 1.4.1? Anything lower and that code will not work.