多选择器与jQuery [英] Multiple Selectors with jQuery
本文介绍了多选择器与jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以一次用Jquery选择两个元素吗?
Can I select two elements with Jquery at the one time?
例如我试过这个,但它只选择了第一个元素:
For example I tried this but it only selected the first element:
$('.loginStaff' || '.loginClient').click(function(){
$('.login_form').toggle();
});
我也试过,但这只选择了最后一个元素:
I also tried but this only selected the last element:
$('.loginStaff' && '.loginClient').click(function(){
$('.login_form').toggle();
});
谢谢!
全局
Thanks!!! Global
推荐答案
只需使用逗号分隔选择器,它将匹配所有结果: p>
Just use a comma to separate your selectors and it will match the combined results of all:
$('.loginStaff,.loginClient').click(function(){
//..
});
更多信息:
- Selectors/multiple
这篇关于多选择器与jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文