这是代码。我要做的是将商品管理后面的<span></span>中的checkbox全部打钩。用next()为什么打印出来都是null
[code=JScript][<script language="javascript">
$(document).ready(function() {
$("tr").click(function(e) {
if ($(e.target).attr("id") == "check") {
if (e.target.checked){
alert($(this).next("span").attr('id'));
$(this).find(":checkbox").attr("checked", true);
$(this).next("span[id='subMenu']").find(":checkbox").attr("checked",true);
}
else{
$(this).find(":checkbox[id!='check']").attr("checked", false);
$(this).closest("span[id='subMenu']").find(":checkbox").attr("checked",false);
}
}
});});
</script>
</head><body>
<table width="100%">
<span>
<tr>
<td width="15%" align="left" BACKGROUND="#99cc99">
--------基础数据
</td>
<td align="left" BACKGROUND="#99cc99" id="s">
<input type="checkbox" name="checkall" onclick="selectSubAll(this)"/>
全选
</td>
</tr>
<tr id="39">
<td>
<input type="checkbox" id="check" value="" />
员工管理
</td>
<td>
<input type="checkbox" name="check_1"
value="1" />浏览
<input type="checkbox" name="check_1"
value="2" />编辑
<input type="checkbox" name="check_1"
value="14" />打印
</td>
</tr>
<tr id="35">
<td>
<input type="checkbox" id="check" value="" />
商品管理
</td>
<td>
<input type="checkbox" name="check_1"
value="1" />浏览
<input type="checkbox" name="check_1"
value="2" />编辑
<input type="checkbox" name="check_1"
value="14" />打印
</td>
</tr>
<span id="subMenu">
<tr id="14">
<td>
<input type="checkbox" id="check" value="" />
规格管理
</td>
<td>
<input type="checkbox" name="check_1"
value="1" />浏览
<input type="checkbox" name="check_1"
value="2" />编辑
<input type="checkbox" name="check_1"
value="14" />打印
</td>
</tr>
<tr id="9">
<td>
<input type="checkbox" id="check" value="" />
尺码管理
</td>
<td>
<input type="checkbox" name="check_1"
value="1" />浏览
<input type="checkbox" name="check_1"
value="2" />编辑
<input type="checkbox" name="check_1"
value="14" />打印
</td>
</tr>
</span>
</span>
</table>/code]
[code=JScript][<script language="javascript">
$(document).ready(function() {
$("tr").click(function(e) {
if ($(e.target).attr("id") == "check") {
if (e.target.checked){
alert($(this).next("span").attr('id'));
$(this).find(":checkbox").attr("checked", true);
$(this).next("span[id='subMenu']").find(":checkbox").attr("checked",true);
}
else{
$(this).find(":checkbox[id!='check']").attr("checked", false);
$(this).closest("span[id='subMenu']").find(":checkbox").attr("checked",false);
}
}
});});
</script>
</head><body>
<table width="100%">
<span>
<tr>
<td width="15%" align="left" BACKGROUND="#99cc99">
--------基础数据
</td>
<td align="left" BACKGROUND="#99cc99" id="s">
<input type="checkbox" name="checkall" onclick="selectSubAll(this)"/>
全选
</td>
</tr>
<tr id="39">
<td>
<input type="checkbox" id="check" value="" />
员工管理
</td>
<td>
<input type="checkbox" name="check_1"
value="1" />浏览
<input type="checkbox" name="check_1"
value="2" />编辑
<input type="checkbox" name="check_1"
value="14" />打印
</td>
</tr>
<tr id="35">
<td>
<input type="checkbox" id="check" value="" />
商品管理
</td>
<td>
<input type="checkbox" name="check_1"
value="1" />浏览
<input type="checkbox" name="check_1"
value="2" />编辑
<input type="checkbox" name="check_1"
value="14" />打印
</td>
</tr>
<span id="subMenu">
<tr id="14">
<td>
<input type="checkbox" id="check" value="" />
规格管理
</td>
<td>
<input type="checkbox" name="check_1"
value="1" />浏览
<input type="checkbox" name="check_1"
value="2" />编辑
<input type="checkbox" name="check_1"
value="14" />打印
</td>
</tr>
<tr id="9">
<td>
<input type="checkbox" id="check" value="" />
尺码管理
</td>
<td>
<input type="checkbox" name="check_1"
value="1" />浏览
<input type="checkbox" name="check_1"
value="2" />编辑
<input type="checkbox" name="check_1"
value="14" />打印
</td>
</tr>
</span>
</span>
</table>/code]
还是引用那个td对象或者直接checkbox对象?
alert($(this).next().attr('id'));
$(this).find(":checkbox").attr("checked", true);
$(this).next("span[id='subMenu']").find(":checkbox").attr("checked",true);
}
else{
$(this).find(":checkbox[id!='check']").attr("checked", false);
$(this).closest("span[id='subMenu']").find(":checkbox").attr("checked",false);
}
发现就到下一个是span时报null。下一个是tr时都正常(alert出tr的id)