[英]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.