假设我有一个点击处理程序:
$('some_selector').click(function(){
});
在处理程序内部,我可以使用$(this)
来选择被单击的元素。
有没有办法在1个语句中选择被点击的元素和其他内容?也许,比如:
$(this, 'some_other_selector')
答案 0 :(得分:9)
使用.add()
例如
$('some_selector').click(function(){
$(this).add('some_other_selector');
});
答案 1 :(得分:0)
而不是.add()
你也可以这样做:
$([ this, $(selector)[0] ])
我更喜欢.add()
,因为上述方法仅限于只返回1个元素的选择器。
它的工作原理是因为你可以将DOMElement
的数组传递给jQuery。