在我的项目中,我们使用 spring、JSTL、bootstrap 和 jquery。在弹簧控制器的后端,我将食物值列表分配给键“foodList”。在 UI 中,我正在对其进行迭代并显示该值。
我将字段“重量”作为文本输入。默认值将打印从后端设置的任何内容。如果用户想要更改,他可以这样做。
当用户更改值时,我想获取修改后的值,但在 jquery 代码中,我总是获取默认值,而不是用户更新的值。
有人可以帮助我的代码有什么问题。
HTML代码,
<table id="table_food"
class="table table-bordered">
<thead>
<tr>
<th>Quantity</th>
<th>Food Name</th>
</tr>
</thead>
<tbody>
<c:forEach items="${foodList}" var="det">
<tr class="clickable-row" id="${det.id}">
<td><input type="text" class="inputWeight"
value="${det.weight}" id="abcd" /></td>
<td><div data-toggle="tooltip" data-placement="top"
title="${det.desc}" class="trunc">
<c:out value="${det.desc}" />
</div></td>
</c:forEach>
</tbody>
</table>
jQuery 代码,
$(document).ready(function(){
$(".inputWeight").change(function(){
alert($(this).val()); });
});
您的 jQuery 代码没有问题。未获得所需输出背后的原因是您实际上将输入值与变量绑定,只需做一件事将先前的数据放入占位符值并将值属性设置为空白
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句