我正在使用jQuery点击函数,我想知道我是否可以使用术语'this‘来选择导航元素和另一个选择器,这是我的代码:
$('#nav').click(function() { $(this, '#anotherSelector').hide(); });
这不管用。它同时选择#anotherSelector而不是#nav元素。我做错了什么?
#anotherSelector
#nav
在此之前,非常感谢您。
发布于 2010-11-26 22:53:12
使用.add()将另一个选择器添加到您要处理的元素集中,如下所示:
.add()
$('#nav').click(function() { $(this).add('#anotherSelector').hide(); });
发布于 2010-11-26 22:53:21
请改用$(this).add('#anotherSelector').hide();。
$(this).add('#anotherSelector').hide();
请参阅add
您现在得到的内容是“搜索DOM元素(this),它位于ID为anotherSelector的元素内。”;有关更多信息,请参阅here。
发布于 2010-11-26 22:55:28
您可以使用add()函数来扩展选择范围
https://stackoverflow.com/questions/4286253
相似问题