以下代码是jmesa对象生成的html代码,table的id是拼接的字符串,并且页面取不到。现在的问题是:有2个全选功能的复选框,用jQuery写的代码,选哪一个,所有的checkbox都会被选中,但是我要的是选中第一个table里的全选checkbox只有同一table里的checkbox被选中。求大虾救我~~~
<form id="form">
<table id="appoint1630" class="table">
<thead>
<tr class="header">
<td><div><input class="cba" type="checkbox"></div></td>
</tr>
</thead>
<tbody class="tbody">
<tr id="appoint1630_row1" class="odd" >
<td><input name="id" type="checkbox"></td>
</tr>
<tr id="appoint1630_row2" class="odd" >
<td><input name="id" type="checkbox"></td>
</tr>
</tbody>
</table>
<table id="appoint1631" class="table">
<thead>
<tr class="header">
<td><div><input class="cba" type="checkbox"></div></td>
</tr>
</thead>
<tbody class="tbody">
<tr id="appoint1631_row1" class="odd" >
<td><input name="id" type="checkbox"></td>
</tr>
<tr id="appoint1631_row2" class="odd" >
<td><input name="id" type="checkbox"></td>
</tr>
</tbody>
</table>
</form>

解决方案 »

  1.   

    $("table:eq(0) :checkbox").attr("checked","checked");
      

  2.   


    <html xmlns="http://www.w3.org/1999/xhtml ">
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
    <title></title>
    <script type="text/javascript">
       jQuery(function($) {
            $("table").each(function(i){
               $(this).find(":checkbox:first").click( function () {
                    $("table").eq(i).find(":checkbox").attr("checked",$(this).attr("checked"));
               }); 
            }); 
        }); 
    </script>
    </head>
    <body>
    <form id="form">
    <table id="appoint1630" class="table">
    <thead>
    <tr class="header">
    <td><div><input class="cba" type="checkbox"></div></td>
    </tr>
    </thead>
    <tbody class="tbody">
    <tr id="appoint1630_row1" class="odd" >
    <td><input name="id" type="checkbox"></td>
    </tr>
    <tr id="appoint1630_row2" class="odd" >
    <td><input name="id" type="checkbox" ></td>
    </tr>
    </tbody>
    </table>
    <table id="appoint1631" class="table">
    <thead>
    <tr class="header">
    <td><div><input class="cba" type="checkbox"></div></td>
    </tr>
    </thead>
    <tbody class="tbody">
    <tr id="appoint1631_row1" class="odd" >
    <td><input name="id" type="checkbox"></td>
    </tr>
    <tr id="appoint1631_row2" class="odd" >
    <td><input name="id" type="checkbox"></td>
    </tr>
    </tbody>
    </table>
    </form>
    </body>
    </html> 这样 ?
      

  3.   

    zell419的代码还是有点问题,选第二个table就可以,选第一个还是全选。
      

  4.   

    这个form里可能有多个table,每个table代表一个预约时间段,每个时间段里会有多个预约,因为table的id不好取到,所以最开始的代码造成选任意全选checkbox,都会使所有的checkbox选中。用你的代码,只有在第二个table里才能正常,第一个还是全选。