jquery实现checkbox全选,反选(转载)
以前网上找到,具体地址忘了
<script src="jquery.min.js" ></script>
<script>
//全选
function selectAll()
{//#wx_list是存放checkbox的父元素
$("#wx_list").find("input[type=checkbox]").each(
function()
{
if(!this.disabled){//排除禁用项
$(this).prop("checked", true);
}
}
);
countChecked();//统计选中项数量
}
//反选
function selectInvert()
{
$("#wx_list").find("input[type=checkbox]").each(function(){this.checked = !this.checked});
countChecked();//统计选中项数量
}
//统计选中项数量,在checkbox的onchange属性中也要调用这个函数
function countChecked()
{//#msg是一个span
$('#msg').text("选中"+$('input[type=checkbox]:checked').length+'项('+(new Date()).toLocaleString()+')');//提示消息+本地时间
}
</script>

浙公网安备 33010602011771号