2012-03-06 88 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/