<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<input type="text" name="ISBN" id="ISBN"/>
<input type="text" name="bookname" id="bookname"/>
<button id="add">增加</button>
<table id="tb1">
<theader>
<tr>
<td><input type="checkbox" name="chkall" id="chkall"></td>
<td>
ISBN
</td>
<td>
书名
</td>
<td>删除</td>
</tr>
</theader>
</table>
<button id="delAll">删除</button>
<script> $(document).ready(function(){ $("#add").click(function(){ var chk = $("input[type='checkbox'][value='"+ $("#ISBN").val() +"']"); if (chk.length !=0 ) { $(chk).parent().next().next().html($("#bookname").val()); } else { var str="<tr>" + "<td><input type='checkbox' name='chkBook'" + "value='"+$("#ISBN").val()+ "'></td>" + "<td>" + $("#ISBN").val() + "</td>" + "<td>" + $("#bookname").val() + "</td>" + "<td><button data-role='del'>x</button></td>" $("#tb1").append(str); } }); $("#chkall").click(function(){ console.log($("#chkall:checked")); $("input[name='chkBook']").prop("checked",$(this).prop("checked")); }) $("#delAll").click(function(){ $("input[name='chkBook']:checked").parents("tr").remove(); }); $("#tb1").on("click",function(event){ console.log(event); console.log() if (event.target.getAttribute("data-role") == "del") { $(event.target).parents("tr").remove(); } }) }) function delTr(obj) { $(obj).parents("tr").remove(); } </script>
</body>
</html>
