1から5までの数量が選択されたときに合計価格を動的に調整しようとしています。私はJqueryを使用することに新しいですので、どんな助けも大歓迎です、ありがとうございます!Jqueryを使用して数量オプションリストで総価格を設定する方法
HTML:
<table>
<thead>
<tr>
<th>Quantity</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<select id="quantity">
<option data-quantity="1">1</option>
<option data-quantity="2">2</option>
<option data-quantity="3">3</option>
<option data-quantity="4">4</option>
</select>
</td>
<td id="price" data-price="@i.Price">[email protected]</td>
</tr>
</tbody>
</table>
<p>Total Price: $<span id="total></span></p>
JAVASCRIPT:問題は、この行var p = $("#price").find("[data-price]")
であるように思わ
<script>
$(document).ready(function() {
var p = $("#price").find("[data-price]")
$("#quantity").change(function() {
var q = $(this).find(':selected').data('quantity');
var total = p * q;
$("#total").text(total);
});
});
</script>
'VARのP =数($( "#価格")のデータ( '価格'));' –