JS实现点击table中任意元素选中

上项目开发,忙的焦头烂额,博客也没咋更新了。

昨天老师提了个需求,简单的小例子,选择tr中任一行选中tr,觉得很有意思,记录一下:

上代码

<!DOCTYPE html>
<html>
<head>
	<title>更新checked</title>
</head>
<script src="E:java jarjqueryjquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(document).on("click","#table1 tr td:not(:first-child)",function(){
	var obj = $(this).parent().find("td:first").find("input");
    obj.prop("checked", !obj.is(":checked"));
})
</script>
<body>
<table id="table1" border="1px">
<tr id="tr1">
<td><input type="checkbox" name="stuId"></td>
<td><p id="stuName" name="stuName">StudentName</p></td>
<td><p id="stuNo" name="stuNo">StudentNo</p></td>
<td><p id="stugrade" name="stugrade">StudentNo</p></td>
</tr>
</table>
</body>
</html>

 作用就是选择tr中任意部分,选中此条记录。

原文地址:https://www.cnblogs.com/longlyseul/p/11538218.html