JS實現點擊table中任意元素選中


上項目開發,忙的焦頭爛額,博客也沒咋更新了。

昨天老師提了個需求,簡單的小例子,選擇tr中任一行選中tr,覺得很有意思,記錄一下:

上代碼

<!DOCTYPE html>
<html>
<head>
	<title>更新checked</title>
</head>
<script src="E:\java jar\jquery\jquery-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中任意部分,選中此條記錄。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM