上項目開發,忙的焦頭爛額,博客也沒咋更新了。
昨天老師提了個需求,簡單的小例子,選擇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中任意部分,選中此條記錄。