Jquery LIVE 与 $(this) 的问题
我有一个问题,我使用 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为您发布的代码是实际运行的,它可以工作:)您可以在这里测试它: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?