这次我需要帮助来完成脚本,我在HTML页面中获得了此表
<div class="Productos">
<table id="products" width="100%" cellspacing="0" cellpadding="0" border="0">
<thead>
<tr>
<th class="left">Prod</th>
<th>
<center>Desc</center>
</th>
<th>qty</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="javascript:popUp2('some_link_here','700','400');"><input type="text" name="f_prod_id" size="10" value="5060102" readonly></td>
<td class="left">desc1</a></td>
<td>
<input type="number" name="f_qty" min="1" max="9999" step="1">
</td>
<td>35.17</td>
</tr>
<tr>
<td><a href="javascript:popUp2('some_link_here','700','400');"><input type="text" name="f_prod_id" size="10" value="5060101" readonly></td>
<td class="left">desc2</a></td>
<td>
<input type="number" name="f_qty" min="1" max="9999" step="1">
</td>
<td>18.48</td>
</tr>
</tbody>
</table>
</div>
我需要做的是清理物品的价值f_qty
。我正在使用以下语法来完成它:
$('#f_qty').val('');
但这是行不通的。在我的HTML屏幕上,我的旧值仍然存在。有什么建议?
这是我的JavaScript:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Totalizar</title>
<script type="text/javascript">
$(function () {
$("#Calculate").click(
// move value
function () {
$("input[name=f_qty]").each(function () {
var valueInCurrentTextBox = $(this).val();
var productId = $(this).find(".f_prod_id").text();
if (valueInCurrentTextBox != '') {
$("#P23_qty").val(valueInCurrentTextBox);
alert('codid : ' + (productId));
$('#f_qty').val('');
}
});
});
});
</script>
</head>
<body>
<div id="totals"></div>
<p style="clear: both;">
<button type="button" style="font-weight: bold; width: auto;" id="Calculate">Agregar Productos</button></p>
</body>
</html>
f_qty
不是输入id
,而是name
输入的。因此,您需要使用属性选择器而不是ID选择器。
$('[name="f_qty"]').val('');
我还注意到,您已经在使用该选择器来遍历元素,因此您可以简单地使用 $(this).val('')
另外,var productId = $(this).find(".f_prod_id").text();
由于this
提供的功能each
将是一个input
元素,而输入元素不能包含子元素,因此这很令人头疼。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句