87,907
社区成员
发帖
与我相关
我的任务
分享
<tr>
<td >
<ul>
<li><input type="checkbox" name="subCheckBox8">增加</input></li>
<li><input type="checkbox" name="subCheckBox8">不变</input></li>
<li><input type="checkbox" name="subCheckBox8">减少</input></li>
<li><input type="checkbox" name="AllSelect8">全部</input></li>
</ul>
</td>
<td >
<ul>
<li><input type="checkbox" name="subCheckBox9">增加</input></li>
<li><input type="checkbox" name="subCheckBox9">不变</input></li>
<li><input type="checkbox" name="subCheckBox9">减少</input></li>
<li><input type="checkbox" name="AllSelect9">全部</input></li>
</ul>
</td>
<td >
<ul>
<li><input type="checkbox" name="subCheckBox10">增加</input></li>
<li><input type="checkbox" name="subCheckBox10">不变</input></li>
<li><input type="checkbox" name="subCheckBox10">减少</input></li>
<li><input type="checkbox" name="AllSelect10">全部</input></li>
</ul>
</td>
<td >
<ul>
<li><input type="checkbox" name="subCheckBox11">增加</input></li>
<li><input type="checkbox" name="subCheckBox11">不变</input></li>
<li><input type="checkbox" name="subCheckBox11">减少</input></li>
<li><input type="checkbox" name="AllSelect11">全部</input></li>
</ul>
</td>
<td >
<ul>
<li><input type="checkbox" name="subCheckBox12">增加</input></li>
<li><input type="checkbox" name="subCheckBox12">不变</input></li>
<li><input type="checkbox" name="subCheckBox12">减少</input></li>
<li><input type="checkbox" name="AllSelect12">全部</input></li>
</ul>
</td>
<td >
<ul>
<li><input type="checkbox" name="subCheckBox13">增加</input></li>
<li><input type="checkbox" name="subCheckBox13">不变</input></li>
<li><input type="checkbox" name="subCheckBox13">减少</input></li>
<li><input type="checkbox" name="AllSelect13">全部</input></li>
</ul>
</td>
<td >
<ul>
<li><input type="checkbox" name="subCheckBox14">增加</input></li>
<li><input type="checkbox" name="subCheckBox14">不变</input></li>
<li><input type="checkbox" name="subCheckBox14">减少</input></li>
<li><input type="checkbox" name="AllSelect14">全部</input></li>
</ul>
</td>
<td >
<ul>
<li><input type="checkbox" name="subCheckBox15">增加</input></li>
<li><input type="checkbox" name="subCheckBox15">不变</input></li>
<li><input type="checkbox" name="subCheckBox15">减少</input></li>
<li><input type="checkbox" name="AllSelect15">全部</input></li>
</ul>
</td>
<td >
<ul>
<li><input type="checkbox" name="subCheckBox16">增加</input></li>
<li><input type="checkbox" name="subCheckBox16">不变</input></li>
<li><input type="checkbox" name="subCheckBox16">减少</input></li>
<li><input type="checkbox" name="AllSelect16">全部</input></li>
</ul>
</td>
</tr>
$('input[name="AllSelect16"]').click(function(){
if($(this).is(':checked')){
$('input[name="subCheckBox16"]').each(function(){
//此处如果用attr,会出现第三次失效的情况
$(this).prop("checked",true);
});
}else{
$('input[name="subCheckBox16"]').each(function(){
$(this).removeAttr("checked",false);
});
}
});
$('input[name="AllSelect17"]').click(function(){
//alert(this.checked);
if($(this).is(':checked')){
$('input[name="subCheckBox17"]').each(function(){
//此处如果用attr,会出现第三次失效的情况
$(this).prop("checked",true);
});
}else{
$('input[name="subCheckBox17"]').each(function(){
$(this).removeAttr("checked",false);
});
}
});
$('input[name^=AllSelect]').click(function() {
$(this).parent().siblings().prop('checked', this.checked);
});
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<table>
<tr>
<td>
<ul>
<li>
<label>
<input type="checkbox" />增加</label></li>
<li>
<label>
<input type="checkbox" />减少</label></li>
<li>
<label>
<input type="checkbox" />不变</label></li>
<li>
<label>
<input type="checkbox" class="chkAll" />全部</label></li>
</ul>
</td>
<td>
<ul>
<li>
<label>
<input type="checkbox" />增加</label></li>
<li>
<label>
<input type="checkbox" />减少</label></li>
<li>
<label>
<input type="checkbox" />不变</label></li>
<li>
<label>
<input type="checkbox" class="chkAll" />全部</label></li>
</ul>
</td>
<td>
<ul>
<li>
<label>
<input type="checkbox" />增加</label></li>
<li>
<label>
<input type="checkbox" />减少</label></li>
<li>
<label>
<input type="checkbox" />不变</label></li>
<li>
<label>
<input type="checkbox" class="chkAll" />全部</label></li>
</ul>
</td>
<td>
<ul>
<li>
<label>
<input type="checkbox" />增加</label></li>
<li>
<label>
<input type="checkbox" />减少</label></li>
<li>
<label>
<input type="checkbox" />不变</label></li>
<li>
<label>
<input type="checkbox" class="chkAll" />全部</label></li>
</ul>
</td>
<td>
<ul>
<li>
<label>
<input type="checkbox" />增加</label></li>
<li>
<label>
<input type="checkbox" />减少</label></li>
<li>
<label>
<input type="checkbox" />不变</label></li>
<li>
<label>
<input type="checkbox" class="chkAll" />全部</label></li>
</ul>
</td>
<td>
<ul>
<li>
<label>
<input type="checkbox" />增加</label></li>
<li>
<label>
<input type="checkbox" />减少</label></li>
<li>
<label>
<input type="checkbox" />不变</label></li>
<li>
<label>
<input type="checkbox" class="chkAll" />全部</label></li>
</ul>
</td>
<td>
<ul>
<li>
<label>
<input type="checkbox" />增加</label></li>
<li>
<label>
<input type="checkbox" />减少</label></li>
<li>
<label>
<input type="checkbox" />不变</label></li>
<li>
<label>
<input type="checkbox" class="chkAll" />全部</label></li>
</ul>
</td>
<td>
<ul>
<li>
<label>
<input type="checkbox" />增加</label></li>
<li>
<label>
<input type="checkbox" />减少</label></li>
<li>
<label>
<input type="checkbox" />不变</label></li>
<li>
<label>
<input type="checkbox" class="chkAll" />全部</label></li>
</ul>
</td>
<td>
<ul>
<li>
<label>
<input type="checkbox" />增加</label></li>
<li>
<label>
<input type="checkbox" />减少</label></li>
<li>
<label>
<input type="checkbox" />不变</label></li>
<li>
<label>
<input type="checkbox" class="chkAll" />全部</label></li>
</ul>
</td>
</tr>
</table>
</body>
</html>
<script src="../../Script/jquery-1.11.3.min.js"></script>
<script>
$(function () {
$('input:checkbox').click(function () {
if ($(this).hasClass('chkAll')) {
$(this).parentsUntil('td').find('input:checkbox').prop('checked', this.checked);
} else {
if (this.checked == false) {
$(this).parentsUntil('td').find('input:checkbox.chkAll').prop('checked', false);
}
}
});
});
</script>
$('input[name^=AllSelect]').click(function() {
$(this).closest('ul').find('input[name^=subCheckBox]').prop('checked', this.checked);
});