2012-03-06 83 views

回答

2
$('form[name="formName"] :checkbox').each(function() { });

0
$('form[name="formName"] input:checkbox').each(function() { 
    //Do something 
}); 

为了获得更好的性能使用输入:复选框。从jquery API:

“$(':checkbox')等价于$('*:checkbox'),所以应该使用$('input:checkbox')。”

0

它可能看起来像:

$('form[name='example'] input[type='checkbox']').each(function(){ 
     //your stuff goes here 
}); 

我不知道的这对性能的影响,虽然。这些依赖于jQuery attribute selectors

1
<input type="checkbox" name="s" id="1" /> 
<input type="checkbox" name="s" id="2" /> 
<input type="checkbox" name="p" id="3" /> 
<input type="checkbox" name="p" id="4" /> 
<input type="checkbox" name="s" id="5" /> 
<input type="checkbox" name="s" id="6" /> 

和脚本

$('#formId input[name=s]').each(function(index){ 
     alert($(this).attr("id")) 
    }); 

下面是示例的http:http://jsfiddle.net/Crwy4/2/