这是布局
页面
添加表格
想要在点击提交按钮后,alert弹出最后一行的用户名 input中输入的值 (现在只能通过id 获取第一行的值)
//最后一行第1个input
document.querySelector("#testTb1 tr:last-of-type input:first-of-type").value
//最后一行第n个input
document.querySelector("#testTb1 tr:last-of-type input:nth-of-type(n)").value
你可以获取到table然后直接通过lastElementChild属性拿到最后一个tr
然后在通过这个tr去获取到他下面的所有的输入框信息
1.在id上拼接上当前行 比如第二行id就是user-2。
2.在获取值的时候 要获取第几行就可以拼接id获取第几行对应的值