jQuery實現表格行點選選中複選框
阿新 • • 發佈:2019-02-16
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>