我有一个输入字段,我想填充表单中较早出现的两个输入字段的乘积。使用jQuery计算javascript中两个输入字段的乘积
<div class="form-group">
<label for="item_name" class="col-lg-2 control-label">Item:</label>
<div class="col-lg-2">
<input type="text" name="item_name[]" placeholder="Name">
</div>
<div class="col-lg-2">
<input type="text" name="item_qty[]" placeholder="Quantity">
</div>
<div class="col-lg-2">
<input type="text" name="item_price[]" placeholder="Price">
</div>
<div class="col-lg-2">
<input type="text" name="item_total[]" placeholder="Total">
</div>
</div>
这些输入字段可以出现多次,所以我试图环比item_total[]
arrray和附加一个侦听焦点事件。
$.each($("[name='item_total[]']"), function(index, value) {
$(this).focus(function() {
var value = ?
//not sure how to select the value of the two previous input fields
// var value = $("item_qty[index]") * $("item_price[index]");
console.log(value);
});
});
,而不是总文本框的重点做了计算上的数量和价格的文本框变化 – 2014-10-16 23:47:40
一旦我得到它的工作在这里,我会重构它应对变化的事件 - 由于 – Luke 2014-10-16 23:50:28
我加了答案,有一看 – 2014-10-17 00:04:33