题目
代码展示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jQuery/jquery-3.6.0.min.js"></script>
<script>
$(function (){
//全选
$(".all").click(function (){
$(".check").prop("checked",true);
});
//反选
$("#btn_not").click(function (){
$(".check").each(function (){
var flag=$(this).prop("checked");
$(this).prop("checked",!flag);
});
})
//取消(移除全选事件)
$("#btn_defeat").click(function (){
$("#btn_all").off("click");
})
});
</script>
</head>
<body>
<div>
<input type="button" value="全选" id="btn_all" class="all"/>
<input type="button" value="反选" id="btn_not" class="not"/>
<input type="button" value="取消" id="btn_defeat" class="defeat"/>
<table border="1">
<tr>
<th>#</th>
<th>姓名</th>
<th>爱好</th>
</tr>
<tr>
<td><input type="checkbox" class="check" id="check1" /> </td>
<td>郭德纲</td>
<td>开车,京剧</td>
</tr>
<tr>
<td><input type="checkbox" class="check" id="check2"/> </td>
<td>岳云鹏</td>
<td>做饭</td>
</tr>
<tr>
<td><input type="checkbox" class="check" id="check3"/> </td>
<td>于谦</td>
<td>抽烟,喝酒,烫头</td>
</tr>
</table>
</div>
</body>
</html>
实话实说,这道题我没太理解取消的作用到底是啥,我理解为移除事件,我对我的理解不是十分肯定,所以,评论区等待大家的建议