<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="jquery.min.js"></script> </head> <body> <table id="setPermission" class="table marginTop_30"> <tr> <td colspan="5"> <span class="font_bold margin_X10">角色管理</span> <input type="checkbox" id="selectAllTerm"> <label for="selectAllTerm">全选</label> </td> </tr> <tr id="termRow"> <td> <input type="checkbox" name="chTerm" id="dd"> <label>查看学期列表</label> </td> <td> <input type="checkbox" name="chTerm"> <label>添加学期</label> </td> <td> <input type="checkbox" name="chTerm"> <label>修改学期</label> </td> <td> <input type="checkbox" name="chTerm"> <label>删除学期</label> </td> <td> <input type="checkbox" name="chTerm"> <label>停用/启用学期</label> </td> </tr> <tr> <td colspan="5"> <span class="font_bold margin_X10">专业管理</span> <input type="checkbox" id="selectAllSpecialty"> <label for="selectAllSpecialty">全选</label> </td> </tr> <tr id="specialtyRow"> <td> <input type="checkbox" name="chAllSpecialty"> <label>查看专业列表</label> </td> <td> <input type="checkbox" name="chAllSpecialty"> <label>添加专业</label> </td> <td> <input type="checkbox" name="chAllSpecialty"> <label>修改专业</label> </td> <td> <input type="checkbox" name="chAllSpecialty"> <label>删除专业</label> </td> <td> <input type="checkbox" name="chAllSpecialty"> <label>停用/启用专业</label> </td> </tr> </table> <script> var checkList=$("input[name='chTerm']"); function selectAll (id) { $(id).click(function () { checkList.prop("checked", $(id).prop("checked")); hasAll(); }); }; function hasAll(){ var chknum = checkList.length; var Count=0; for(var i=0;i<chknum;i++){ if(checkList[i].checked){ Count++; } } console.log(Count); if(chknum==Count){//全选 $("#selectAllTerm").prop("checked",true); }else{//不全选 $("#selectAllTerm").prop("checked",false); } } selectAll(selectAllTerm); selectAll(selectAllSpecialty); $(function(){ $("input[name='chTerm']").each(function(){ $(this).click(function(){ hasAll(); }) }) }) </script> </body> </html>
宝慕林2233867
相关分类