我如何获得jquery中的数组复选框值

时间:2014-06-20 21:24:34

标签: javascript jquery checkbox

我是Jquery的新手。我有这种复选框数组

<input type="checkbox" name="propertyfeatures[Appliances]" value="Dishwasher">
<input type="checkbox" name="propertyfeatures[Appliances]" value="Dryer" > 
<input type="checkbox" name="propertyfeatures[Appliances]" value="Freezer">
<input type="checkbox" name="propertyfeatures[Appliances]" value="Garbage disposal" >
<input type="checkbox" name="propertyfeatures[Appliances]" value="Microwave"> 
<input type="checkbox" name="propertyfeatures[Appliances]" value="Range / Oven" >
<input type="checkbox" name="propertyfeatures[Appliances]" value="Refrigerator">
<input type="checkbox" name="propertyfeatures[Appliances]" value="Trash compactor" >
<input type="checkbox" name="propertyfeatures[Appliances]" value="Washer">
<input type="checkbox" name="propertyfeatures[Appliances]" value="None" >

如果选中“无复选框”,我将如何在jquery中获取所有Appliances数组值

1 个答案:

答案 0 :(得分:0)

的jsfiddle:

http://jsfiddle.net/8KYzp/2/

None复选框设为ID,例如save_value

<input type="checkbox" name="propertyfeatures[Appliances]" value="None" id="save_value">

$(function(){
  $('#save_value').click(function(){
    var val = [];
    $(':checkbox:checked').each(function(i){
      val[i] = $(this).val();
        alert(val[i]);
    });
  });
});