[英]jQuery: How can I select multiple elements from one path?
I'm curious if there is a way to condense this: 我很好奇是否有一种方法可以将其压缩:
$('foo input:checkbox, foo input:radio');
I tried the following but no luck: 我尝试了以下方法,但没有运气:
$('foo input[type="checkbox",type="radio"]');
This blindly doesn't work (prob bad syntax) 这盲目行不通(可能语法错误)
$('foo input[type="checkbox"][type="radio"]');
I think this would select all inputs that are both radio and checkbox, which won't ever be the case. 我认为这会选择所有既是单选又是复选框的输入,但事实并非如此。
Edit: 编辑:
I changed fooElement
to foo
toi simplify the example 我将
fooElement
更改为foo
toi简化了示例
$('input[type="checkbox"], input[type="radio"]', $('fooelement'))
Or 要么
$('[type="checkbox"], [type="radio"]', $('fooelement input'))
Or 要么
$(':checkbox, :radio', $('fooelement input'))
Remember jQuery offers the abiltiy to specify a context to search in. 请记住,jQuery提供了指定要搜索的上下文的能力。
尝试这个
$('fooElement input').filter(":checkbox, :radio");
$('fooElement').find(':checkbox,:radio');
$('fooElement input[type="checkbox"]').add('fooElement [type="radio"]');
它本身并不是真正的“压缩”,而是:
$('fooElement input[type="checkbox"], fooElement input[type="radio"]');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.