製品の説明と価格を表示するセレクト ボックスがあります。ユーザーの選択内容に応じて、選択したオプションからその金額を自動的に取得し、価格入力フィールドに割り当てたいと考えています。私のHTML:
<tr>
<td>
<select class="selector">
<option value="Item One $500">Item One $500</option>
<option value="Item Two $400">Item Two $400</option>
</select>
</td>
<td>
<input type="text" class="price"></input>
</td>
</tr>
したがって、選択内容に基づいて、.class 入力に 500 または 400 を割り当てます。私はこれを試しましたが、どこが間違っているのかよくわかりません:
$('.selector').blur(function(){
var selectVal = ('.selector > option.val()');
var parsedPrice = parseFloat(selectVal.val());
$('.price').val(parsedPrice);
});