[英]jQuery: How can I select multiple elements from one path?
我很好奇是否有一种方法可以将其压缩:
$('foo input:checkbox, foo input:radio');
我尝试了以下方法,但没有运气:
$('foo input[type="checkbox",type="radio"]');
这盲目行不通(可能语法错误)
$('foo input[type="checkbox"][type="radio"]');
我认为这会选择所有既是单选又是复选框的输入,但事实并非如此。
编辑:
我将fooElement
更改为foo
toi简化了示例
$('input[type="checkbox"], input[type="radio"]', $('fooelement'))
要么
$('[type="checkbox"], [type="radio"]', $('fooelement input'))
要么
$(':checkbox, :radio', $('fooelement input'))
请记住,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.