I am working on cr开发者_JS百科eating a selector to select all the checkboxes with the a name in the form with an id. I do have multiple forms with the same name for the checkbox. So trying to figure out how I would get all the check boxes within a given form with an id. I have used something like this which doesnt work.
$('#formID input[type="checkbox"][name="inputName"]').each(function(idx){
if($(this).is(':checked')){
alert($(this).val());
}
});
$("#formID input:checkbox[name='name']")
should work. I dont see why yours doesnt though.
Check out this code - hopefully it shows you a working example that you may use:
http://jsbin.com/uqife3/edit
$('#1 input[type="checkbox"]').each(function(){
if($(this).attr('name') == 'check1'){
$(this).attr('checked', true);
alert('bla'+$(this).attr('name'));
}
});
精彩评论