鉴于以下形式,我如何选择所有标签,除了紧接在复选框或无线电输入之前的标签。
<form>
<label>Select This Label</label><input type="text" />
<label>Select This Label</label><input type="email" />
<label>Select This Label Main checkbox group</label><br>
<label>NOT THIS LABEL!</label><input type="checkbox" />
<label>NOT THIS LABEL!</label><input type="radio" />
<label>Select this arbitrary label just hanging out here</label>
</form>
目标:我正在尝试向除标签4和5之外的所有标签添加一个类。
编辑:我尝试过的选择器在不同的地方使用+和:not()运算符。所以
$( form label +:not(input[type=radio],input[type=checkbox]) ~ label)
或
$( form label:not(+input[type=radio],+input[type=checkbox]) ~ label)
等。
编辑2 *我需要在选择器中完全执行此操作。
答案 0 :(得分:1)
尝试:
$("form").find("label").each(function(){
if(!($(this).next().is("input[type='radio']") || ($(this).next().is("input[type='checkbox']")))){
$(this).addClass("someclass");
}
});
答案 1 :(得分:0)
我认为只使用选择器
是不可能的$('label').filter(function(){
return !$(this).next().is('[type="radio"], [type="checkbox"]')
})
演示:Fiddle