【发布时间】:2014-12-29 18:17:44
【问题描述】:
我想要的是,当型号改变时,价格的价值也会改变。而要获得价格,我需要身份证号和数量。
所以我得到了这个 HTML 代码:
<div class="col-sm-9 topnav">
<span>
<input name="prodid[]" type="text" id="form-field-icon-1" class="input-small" placeholder="Product ID" />
</span>
<span>
<input name="model[]" type="text" id="form-field-icon-2" class="input-small" onchange="getprice($(this));"placeholder="Model" />
</span>
<span>
<input name="qty[]" type="text" id="form-field-icon-3" class="input-small" placeholder="Quantity" />
</span>
<input name="price[]" type="text" id="form-field-icon-2" class="input-small" placeholder="Price" readonly="readonly" />
<span>
<button class="btn btn-minier btn-yellow">Add</button>
</span>
</div>
JS代码:
function getprice(thisObj) {
var prodid = thisObj.closest('div').children().children("input:first").val();
var modelid = thisObj.val();
var qty = thisObj.closest('div').children().children("input:nth-child(2)").val();
}
我得到的 qty 的值是未定义的,但是当我将第 n 个孩子更改为 1 时,我得到了我输入的值。在我的 console.log 中,有一个值。 上下文:输入#form-field-icon-2.input-small
非常感谢您的帮助!
【问题讨论】:
标签: javascript jquery html css-selectors