龙空技术网

checkbox 的全选功能实现,支持半勾选状态

爱码僧 49

前言:

眼前咱们对“td隐藏js”大概比较重视,你们都想要分析一些“td隐藏js”的相关内容。那么小编也在网摘上搜集了一些关于“td隐藏js””的相关内容,希望朋友们能喜欢,各位老铁们一起来了解一下吧!

支持IE浏览器

效果图:

html 表头部分:

<td><input type="checkbox" name="selectAll" id="selectAll" /></td>

html table部分

<td><input type="checkbox" name="serial_no" value="/></td><td><input type="checkbox" name="serial_no" value="/></td><td><input type="checkbox" name="serial_no" value="/></td>

js代码:

因为要实时监控,所以要放在ready函数中去写

	$(function(){		$("#selectAll").click(function() {			if ($(this).is(":checked")) { // 全选				$("input[name='serial_no']").attr("checked", true);			} else { // 取消全选				$("input[name='serial_no']").attr("checked", false);			}		});				$("input[name='serial_no']").click(function(){			var allSel = true;			var selCnt = 0;			$("input[name='serial_no']").each(function() {				if(!$(this).is(":checked")){					allSel = false;				}else{					selCnt++;				}			});						var itn = document.getElementById('selectAll');			if(!allSel){				itn.indeterminate = true;			}else{				itn.indeterminate = false;				$("#selectAll").attr("checked", true);			}			if( selCnt == 0 ){				itn.indeterminate = false;				$("#selectAll").attr("checked", false);			}		});	});

标签: #td隐藏js #checkbox 全选 #css的indeterminate