开发者

jQuery choose the inputs based on a form ID

开发者 https://www.devze.com 2023-02-10 13:52 出处:网络
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

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'));
  }

});
0

精彩评论

暂无评论...
验证码 换一张
取 消