页面代码,列表多选框 <c:forEach items="${list}" var="obj"> <tr id="tr${obj.id}"> <td><input name="searchId" type="checkbox" value="${obj.id}"></td> <td>${obj.product_code}</td> <td style=" word-wrap:break-word;word-break:break-all;white-space: normal">${obj.product_name}</td> <td style=" word-wrap:break-word;word-break:break-all;white-space: normal">${obj.category_name}</td> <td >${obj.old_cost_price}</td> <td >${obj.cost_price}</td> <td >${obj.old_price}</td> <td >${obj.price}</td> <td>${obj.nowPrice}</td> <td >${obj.rebate}</td> <td>${obj.num}</td> </tr> </c:forEach>多选按钮<input type="checkbox" name="checkAll">全选js代码$(function () { //全选按钮实现 $("input[name=checkAll]").click(function () { if (this.checked) { $("input[name=searchId]").prop("checked", true); } else { $("input[name=searchId]").prop("checked", false); } }); //反选实现 $("input[name=searchId]").click(function () { var allCheckBox=$("input[name=searchId]"); var same=true; var temp=allCheckBox[0].checked; for (var i=0;i<allCheckBox.length;i++){ if (allCheckBox[i].checked!==temp){ same=false; break; } } if (same){ $("input[name=checkAll]").prop("checked", temp); } else { $("input[name=checkAll]").prop("checked", false); } });});