以下代码是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>
<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>
<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> 这样 ?