莫菲    

jquery 通过 类 class 获取checkbox选中的值

7年前发布  · 2269 次阅读
  jquery 
html

<input type="checkbox" class="group1" value="1" checked="checked" />
<input type="checkbox" class="group1" value="2" />
<input type="checkbox" class="group1" value="3" />
<input type="checkbox" class="group2" value="4" />
<input type="checkbox" class="group1" value="5" checked="checked" />
<input type="checkbox" class="group1" value="6" checked="checked" />
<input type="checkbox" class="group1" value="7" checked="checked" />
<input type="checkbox" class="group1" value="8" />
js

var values = $('input:checkbox:checked.group1').map(function () {
  return this.value;
}).get();
alert(values);

获取被选中的数目(类)

js

var valuecount=$('input.group1:checked').length;
alert(valuecount);