js代码,页面初始化执行:
$(".list tr").each(function(){
$(this).children().click(function(e){
$(e.target).parent("tr.item").each(function(){
if($(this).find(":checkbox").is(":checked")){
$(this).find(":checkbox").attr("checked",false);
}else{
$(this).find(":checkbox").attr("checked",true);
}
});
});
});
对应表格的jsp代码:
<table class="list" >
<tbody>
<tr >
<th>序号</th>
<th>姓名</th>
<th>性别</th>
<th>地址</th>
</tr>
<c:forEach items= "${finder.mapitems}" var="bean" varStatus="st">
<tr class="item">
<td><input type="checkbox" name="vipId" id="vipId_${st.count}" value="${bean.vipId }"/>${st.count}</td>
<td><label for="vipId_${st.count}">${bean.custName}</label> </td>
<td><label for="vipId_${st.count}">${bean.sexId}</label> </td>
<td><label for="vipId_${st.count}">${bean.custAddr}</label> </td>
</tr>
</c:forEach>
</tbody>
</table>