jquery 点击按钮获取动态添加的 tr中 input text 内容

jquery 点击按钮获取动态添加的 tr中 input text 内容,第1张

按照要求,在点击每一行的修改按钮,需要获取对应行的第一列input的value值,对应的js代码参考下方:

function change(){

   var text = $(this).parents('tr').children('td:eq(0)').children('input').val()

   console.log(text)

}

还有更加简便的方法:在forEach循环生成tr和td元素时,按照如下规则生成td元素:

<c:forEach items="${projectHot26005s}" var="zslb">

<tr id="sj1">

<td><input type="text" id="txt${zslb.projectId}" value="" maxlength="2"></td>

<td>${zslb.projectName }</td>

<td><button class="btn btn-red r3 margin" onclick="btnDelete('${zslb.projectId }')">删除</button></td>

<td><button class="btn btn-red r3 margin" onclick="change('${zslb.projectId}')">修改</button></td>

</tr>

</c:forEach>

这样在change方法中就能通过唯一的id来定位到指定的input,既而获取到value值:

function change(id){

   var text = $("#txt" + id).val()

   console.log(text)

}

可以动态添加完之后,统一绑定事件

$("#tables td").click(function(){

    console.log($(this).text())

})

亦可以每生成一个元素就绑定事件,不过这样你的html需要修改,改为循环插入td

因为clone()的表单name属性都一样

后台取参数要用

String[] names = request.getParamterValues("name")

这种方式接收到的是表单内容数组

如果用

request.getParamter("name")

只接收一个值


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11556221.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存