以下是由PHP产生while循环我的html代码:如何在选择选项更改时更改值?
<select class="menu_extra_item">
<option>--Qnt--</option>
<option>1</option>
<option>2</option>
<option>2</option>
</select>
<select class="menu_extra_item"/>
<option>--Qnt--</option>
<option>1</option>
<option>2</option>
<option>2</option>
</select>
<tr class="menu_extra_item_change">
<td>$32</td>
</tr>
<tr class="menu_extra_item_change">
<td>$10</td>
</tr>
我想改变价值(价格如$ 32)时,选择选项就是变化。
例如,
I select (first select) option `1`then it will be show `$32`
I select (first select) option `2`then it will be show `$62`
I select (second select) option `1`then it will be show `$10`
I select (second select) option `2`then it will be show `$20`
为了得到这个输出我使用下面的jQuery代码,但它不工作我想要什么:(
jQuery代码:
$(".menu_extra_item").each(function() {
$(this).change(function() {
var menu_extra_item =$(this).val();
var menu_extra_item_change = parseInt($('.menu_extra_item_change').text().replace(/[^0-9.]/g, ""));
alert(menu_extra_item_change);
var total_ex_price = menu_extra_item * menu_extra_item_change;
$(".menu_extra_item_change").each(function() {
$(".menu_extra_item_change").text("$"+total_ex_price);
});
});
});
这个心不是一个有效的HTML,你缺失的结束标记。 – Gintoki
更改了@John –
这很简单。只需根据所选的'select''索引()'更改'tr'值。目前你正在改变所有'tr'值在选择'change'上 –