<!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"> <label>查看学期列表</label> </td> <td> <input type="checkbox"> <label>添加学期</label> </td> <td> <input type="checkbox"> <label>修改学期</label> </td> <td> <input type="checkbox"> <label>删除学期</label> </td> <td> <input type="checkbox"> <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"> <label>查看专业列表</label> </td> <td> <input type="checkbox"> <label>添加专业</label> </td> <td> <input type="checkbox"> <label>修改专业</label> </td> <td> <input type="checkbox"> <label>删除专业</label> </td> <td> <input type="checkbox"> <label>停用/启用专业</label> </td> </tr></table><!--如果子选项取消勾选一个,全选按钮就取消勾选;反之全选了子选项,全选按钮默认勾选。这个功能赢该怎么写??--><script> selectAll = function (obj) { var checklist = $(obj).parent().parent().next().find("input[type='checkbox']"); $(obj).click(function () { $(obj).parent().parent().next().find("input[type='checkbox']").prop("checked", $(obj).prop("checked")); }); } selectAll($("#selectAllTerm")); selectAll($("#selectAllSpecialty"));</script></body></html>
2 回答
刚毅87
TA贡献345条经验 获得超309个赞
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <input type="button" value="选择" id="btn"/> <input type="checkbox" name="" id="check" value="" /> </body> <script type="text/javascript"> var btn = document.getElementById('btn'); var check = document.getElementById('check'); //给按钮添加点击事件 btn.onclick = function (){ // alert(check.checked) // check.checked 的选中和非选中状态; // true 选中 false 非选中 //如果选择框为选中状态,且切换为非选中状态 if(check.checked){ //设置非选择双胎 check.checked = false; }else{ //设置选择状态 check.checked = true; } } var bool = true; if (bool) { check.checked = true; bool = false; } else{ check.checked = false; bool = true; } </script> </html>
你参考一下吧.
添加回答
举报
0/150
提交
取消