- 判断是否选中
$('#xingwei').is(':checked') true选中 false 没选中
- 赋值
$("#xingwei").attr("checked",true); 选中
$("#xingwei").attr("checked",false); 取消选中
设置checkbox为启用状态(jquery<1.6用attr,jquery>=1.6建议用prop)
$("input[type='checkbox']").removeAttr("disabled");
$("input[type='checkbox']").attr("disabled", false);
$("input[type='checkbox']").prop("disabled", "");
$("input[type='checkbox']").prop("disabled", false);
设置checkbox为禁用状态(jquery<1.6用attr,jquery>=1.6建议用prop)
$("input[type='checkbox']").attr("disabled", "disabled");
$("input[type='checkbox']").attr("disabled", true);
$("input[type='checkbox']").prop("disabled", true);
$("input[type='checkbox']").prop("disabled", "disabled");
获取多个选中的checkbox值
var vals = [];
$('input:checkbox:checked').each(function (index, item) {
vals.push($(this).val());
});
根据id获取checkbox
$("#cbCheckbox1");
获取所有的checkbox
$("input[type='checkbox']");
$("input[name='cb']");
获取所有选中的checkbox
$("input:checkbox:checked");
$("input:[type='checkbox']:checked");
$("input[type='checkbox']:checked");
$("input:[name='ck']:checked");
获取checkbox值
$("#cbCheckbox1").val();