【发布时间】:2021-10-23 08:19:03
【问题描述】:
我在选择产品后尝试选择并获取价格,并在输入兄弟 tr 上返回价格。
我试试
function getPrice() {
$(this).closest('tr').find('input').val($(this).val());
};
还有nth-child() 的变体,但我不能。
我需要更新价格值
<!-- Django template tags -->
{% for item in items %}
<tr>
<td>
<select name="product" class="form-control" onchange="getPrice()">
<!-- Django template tags -->
{% for product in products %}
<option value="{{product.pk}}">{{ product.title }}</option>
{% endfor %}
</select>
</td>
<td>
<input name="price" class="form-control price" type="number" step="0.01">
</td>
<td>
<input name="quantity" class="form-control" type="number" step="0.01">
</td>
<td>
<span class="span-is-link no" onclick="removeRow()">
<i class="fa fa-close"></i>
</span>
</td>
</tr>
{% endfor %}
<script>
function getPrice() {
// Initial test with get value of select.
// jQuery
// inpuy in equivalent line of tr
$(this).closest('tr').find('input').val($(this).val());
}
</script>
【问题讨论】: