【发布时间】:2015-01-08 20:48:15
【问题描述】:
我正在尝试将输入框的值设置为另一个输入框的值乘以商品的价格。我将货币包裹在一个带有类的跨度标签中。我需要将该值乘以.productTextInput 输入文本框。该值将显示在.subTotal 框中。我该如何做到这一点?
jQuery:
$(".productTextInput").each(function() {
$(this).change(function() {
var priceAmount = $(this).parents().find(".priceAmount").text();
$(this).parents().find(".subTotal").val(parseInt($(this).val(), 10) * parseInt(priceAmount, 10));
});
});
html:
<table class="productTable productSmall" cellspacing="0">
<tbody>
<tr>
<td style="width: 27%;">
<strong>American (wild) plum</strong>
</td>
<td class="custom-tag"></td>
<td class="custom-tag">
Prunus americana
</td>
<td class="custom-tag">
Bare Root
</td>
<td class="custom-tag" style="border-right: 2px solid #000;">
2' - 3' size
</td>
<td style="text-align:right;padding-right: 10px;">
$<span class="priceAmount">1.75</span>
</td>
<td class="quantity">
<input id="Units_4996263" class="productTextInput" name="AddToCart_Amount" value="1" type="text">
</td>
<td>
<input class="subTotal" name="subTotal" readonly="readonly" type="text">
</td>
</tr>
</tbody>
</table>
【问题讨论】:
-
这不是您问题的完整答案,但您没有关闭输入标签。应该是
<input id="id" />/ -
@wahwahwah 如果您不这样做,这实际上不会影响任何事情。很好的建议,因为最好在语法上保持一致,但如果缺少 HTML,HTML 将无错误地呈现。请参阅stackoverflow.com/questions/13232121/… 以更好地理解。
-
@wahwahwah 这是由于系统通过标签生成的输入。我没有包含标签,因为它没有意义。不过感谢您的提醒。
标签: javascript jquery html