带有 jQuery 委托的复杂选择器
jQuery 1.4.2 中可与委托一起使用的选择器的复杂性是否有限制?
这对我有用:
$('.activeTabsList').delegate('.activeTabsListItem', 'click',
function() {
alert('here');
});
这不起作用:
$('.activeTabsList').delegate('.activeTabsListItem:not(.selected)', 'click',
function() {
alert('here');
});
正如您可能假设的那样,一次只有 1 个项目具有所选类别。当我单击其他选项卡时,我的委托处理程序仍然没有被触发。
Is there a restriction on the complexity of selectors that can be used with delegate in jQuery 1.4.2?
This works for me:
$('.activeTabsList').delegate('.activeTabsListItem', 'click',
function() {
alert('here');
});
This does not work:
$('.activeTabsList').delegate('.activeTabsListItem:not(.selected)', 'click',
function() {
alert('here');
});
As you can probably assume, there is only 1 item at a time that has the selected class. When I click the other tabs, my delegate handler is still not fired.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您拥有的代码可以工作,您可以在此处查看演示。确保您的选择器像您认为的那样匹配,这很可能是问题...
。 delegate()
本身处理这种情况。通常,这种情况是由于过度分配
selected
类而导致的:The code you have works, you can see a demo here. Make sure that your selector matches like you think it does, this is most likely the issue...
.delegate()
itself handles this case.Usually this happens as a result of something like this, over-assigning the
selected
class: