
获取 checkbox的选中个数可以直接使用如下jquery语法
$("input[type='checkbox']:checked").length;实例演示如下
创建Html元素
<搜世div class="box">
点击按钮获取选中个数:
萝卜
青菜
小葱
豆腐
土豆

获取 checkbox的选中个数可以直接使用如下jquery语法
$("input[type='checkbox']:checked").length;实例演示如下
创建Html元素
<搜世div class="box">
点击按钮获取选中个数:
萝卜
青菜
小葱
豆腐
土豆
设置css样式
div.box{width:300px;height:250px;padding:10px 20px;margin:20px;border:4px dashed #ccc;}
div.box>span{color:#999;font-style:italic;}
div.content{width:250px;height:100px;margin:10px 0;padding:5px 20px;border:2px solid #ff6666;}
input[type='checkbox']{margin:5px 10px;}
input[type='button']{width:120px;height:30px;margin:10px;border:2px solid #ebbcbe;}编写jquery代码
$(function(){
$("input:button").click(function() {
alert($("input[type='checkbox']:checked").length);
});
})观察效果