html:
<input type="checkbox" value="" name="item"> <input type="checkbox" value="" name="item"> <input type="checkbox" value="" name="item"> <input type="checkbox" value="" name="item"> <input type="checkbox" value="" name="item"> <input type="checkbox" value="" name="item"> <input type="checkbox" name="all">全选
JS:
$(function () { //全选,设置chheckbox name='all' $("input[name=all]").click(function () { $("input[name=item]").prop("checked",this.checked); }); });
历遍选择框:
var id="" $("input[name=item]").each(function (index, element) { if ($(this).prop('checked')) { id += id == "" ? $(this).val() : "," + $(this).val() } }) alert(id)
判断是否选中:
方法一: if($('#checkbox-id').is(':checked')) { // do something } 方法二: if($('#checkbox-id').prop('checked')) { //do something }
这篇文档对您是否有帮助?