这是代码。我要做的是将商品管理后面的<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>
&nbsp;&nbsp;
<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>
&nbsp;&nbsp;
<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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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]

解决方案 »

  1.   

    另:直接用$("span[id='subMenu'] :checkbox") 这样当然可以。但是我有多个span[id='subMenu']
      

  2.   

    我看你的checkbox标签不在span后面啊
      

  3.   

    $("商品管理").nextAll(":checkbox")
      

  4.   

    $("商品管理").nextAll("span :checkbox")
      

  5.   

    你是说引用引用商品管理的那个tr的JQuery对象 后用nextAll 么? 不行。我试了。
    还是引用那个td对象或者直接checkbox对象?
      

  6.   

    我将代码做了如下修改:if (e.target.checked){

        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)