Jquery LIVE 与 $(this) 的问题

发布于 2024-09-08 23:44:53 字数 249 浏览 0 评论 0原文

我有一个问题,我使用 .live() 来绑定 mouseenter,如下所示:

$('a').live('mouseenter',function(e){
  alert($(this).attr('title'));
});

对于我的所有链接,我都会收到第一个链接标题的警报,我认为问题来自 $(this) 但我不确定,有人可以帮忙吗?

I have a problem, I'm using .live() to bind mouseenter like this:

$('a').live('mouseenter',function(e){
  alert($(this).attr('title'));
});

For all my links I get an alert for the first link's title, I think the problem is from $(this) but I'm not sure, can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦罢 2024-09-15 23:44:53

我不认为您发布的代码是实际运行的,它可以工作:)您可以在这里测试它:http://jsfiddle.net/YyMDg/

看看您的实际代码有什么区别,例如您是否在某个地方循环,以及$(this) 不是在处理程序中评估而是在处理程序之外的某个地方评估?

I don't think the code you posted is what's actually running, it works :) You can test it here: http://jsfiddle.net/YyMDg/

See what the difference is in your actual code, are you looping somewhere for example, and $(this) isn't being evaluated in the handler but somewhere outside of it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文