如何使用jquery按值访问复选框
可能重复:如何使用jquery按值访问复选框,jquery,html,Jquery,Html,可能重复: 我将其作为html: <div style="" id="results"> <label class="wList"><input checked="checked" class="wList-chk" name="wList[]" value="6" type="checkbox">Running</label> <label class="wList"><input checke
我将其作为html:
<div style="" id="results">
<label class="wList"><input checked="checked" class="wList-chk" name="wList[]" value="6" type="checkbox">Running</label>
<label class="wList"><input checked="checked" class="wList-chk" name="wList[]" value="1" type="checkbox">Baseball</label>
<label class="wList"><input checked="checked" class="wList-chk" name="wList[]" value="3" type="checkbox">Basketball</label>
</div>
跑步
棒球
篮球
我想通过值访问复选框,我想知道这是如何做到的。我试过:
$(“#results.wList.wList chk input:checkbox”).attr('value').effect('highlight',{},1500)代码>
我做错了什么?您需要实际检查值。像这样:
$('input[type="checkbox"][value="foo"]');
$("#results .wList .wList-chk input:checkbox").each(function(){
value = $(this).val();
if(value==someVal){
$(this).effect('highlight', {}, 1500);
}
});
您需要实际检查该值。像这样:
$("#results .wList .wList-chk input:checkbox").each(function(){
value = $(this).val();
if(value==someVal){
$(this).effect('highlight', {}, 1500);
}
});
有很多方法,其中之一是:
$('input.wList-chk[value="1"]').effect('highlight',{},1500);
但是,这将只选择复选框,而不选择其周围的文本。您可能想要的是:
$('input.wList-chk[value="1"]').parent().effect('highlight',{},1500);
这将选择标签和其中的文本。有很多方法,其中之一是:
$('input.wList-chk[value="1"]').effect('highlight',{},1500);
但是,这将只选择复选框,而不选择其周围的文本。您可能想要的是:
$('input.wList-chk[value="1"]').parent().effect('highlight',{},1500);
这将选择标签和其中的文本。attr
作为getter返回的字符串不具有效果
方法。请阅读:attr
作为getter返回的字符串不具有效果
方法。请阅读:检查“checked”属性而不是属性值是否更安全?也许这里可以使用.filter(“:checked”)
。@Cory无论如何,我在这里看到,检查“checked”属性而不是属性值是否更安全?也许.filter(“:checked”)
可以在这里使用。@Cory反正我在这里看到了