多选框checkbox:$("#checkbox_id").attr("value");
多选框 checkbox: $("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==undefined) //判断是否已经打勾
if($("#licence").attr("checked") == false){
alert('未选择checkbox!');
$('#licence').focus();
return false;
}
判断checkbox选中个数
$(":checkbox[@name=compare]").click(function(){
var checked = this.checked;
id.each(function(){
this.checked = checked;
});
cm(checked);
});
id.click(function(){
var i = 0;
id.each(function(){
this.checked && i++;
})
cm(i>1);
});
看个简单实例
判断checkbox var n = $("input:checked").length;
if(n==0){
alert("未选中!");
}else{
alert("选中!");
}
$("div").text(n + (n <= 1 ? " is" : " are") + " checked!");
3:checkbox数组全选、取消全选
$("#selall").click(function(){
$("input[name='cbox[]']").attr("checked",$(this).attr("checked"));
});
var selected = $('input[name=selectid:checked]').val();//若未被选中 则val() = null
if(selected == null){
alert("未选中!");
}else{
alert("选中!");
}