直接上代码,内容不多,边看边试
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-3.4.1.js" ></script>
<script type="text/javascript">
$(function(){
$(".checkall").click(function(){ //直接设置点击事件 相当于匿名方法
$(".checkone").prop("checked",$(".checkall").prop("checked")) //全选全不选
})
$(".btu").click(function(){ //删除
var lk = $(".checkone")
for (var c = 0;c<lk.length;c++) {
if ($(lk[c]).prop("checked")) {
$(lk[c]).parent().parent().remove() //删除一整行的内容
}
}
})
})
</script>
</head>
<body>
<input type="checkbox" class="checkall" />全选/全不选 <button class="btu" >删除</button>
<table>
<tr>
<th></th>
<th>name</th>
<th>price</th>
<th>date</th>
</tr>
<tr>
<td><input type="checkbox" class="checkone"></td>
<td>product2</td>
<td>2343</td>
<td>2342-4-5</td>
</tr>
<tr>
<td><input type="checkbox" class="checkone"></td>
<td>product1</td>
<td>2343</td>
<td>2342-4-5</td>
</tr><tr>
<td><input type="checkbox" class="checkone"></td>
<td>product3</td>
<td>2343</td>
<td>2342-4-5</td>
</tr>
<tr>
<td><input type="checkbox" class="checkone"></td>
<td>product4</td>
<td>2343</td>
<td>2342-4-5</td>
</tr>
</table>
</body>
</html>