1

Possible Duplicate:
Get a list of all checked values

I have a form with a series of checkboxes all, none or various of which can be checked.

 <p><label for="available_lengths">Rail Length:</label></p>
 <p>
  <ul>    
   <li><label for="id_available_lengths_0"><input name="available_lengths" value="132" id="id_available_lengths_0" type="checkbox" class="can_update_lengths" /> 132</label></li>
   <li><label for="id_available_lengths_1"><input name="available_lengths" value="168" id="id_available_lengths_1" type="checkbox" class="can_update_lengths" /> 168</label></li>
   <li><label for="id_available_lengths_2"><input name="available_lengths" value="208" id="id_available_lengths_2" type="checkbox" class="can_update_lengths" /> 208</label></li>
   <li><label for="id_available_lengths_3"><input name="available_lengths" value="240" id="id_available_lengths_3" type="checkbox" class="can_update_lengths" /> 240</label></li>
  </ul>
 </p>

How do I loop through these and assign a variable the .val() of each?

4

1 回答 1

0

用于$.each迭代 Checkbox 元素

var checkboxValues = [];

$('ul input[type="checkbox"]').each(function() {
     checkboxValues.push(this.value);
});

console.log(checkboxValues );

检查小提琴

于 2012-11-21T22:33:36.530 回答