1. 程式人生 > >28.json數組,select選擇,input輸出對應數據

28.json數組,select選擇,input輸出對應數據

ase readonly bsp tor BE span cte AC ech

效果:選擇對應的車類,下面的input會實時出現車價。

html:

<form action="" class="priceModelform1">
<!-- select選擇 motorcycle1 -->
<select class="motorcycle1" name="motorcycle1" id="motorcycle1" onchange="motorcycleChange1()" >
<option value="">請選擇</option>


<option value="0">汽車</option>
<option value="3">轎車</option>
</select>
<!-- input輸出數據 purchase1 -->
<input class="purchase1" type="number" readonly="readonly" value="">

</form>

js:

var cartConfig={
"0":{"purchaseMoney":10},
"3":{"purchaseMoney":7.5}};
function motorcycleChange1(){
var motorcycle1= $("#motorcycle1 option:selected").val();
//console.log(motorcycle1);
var a= $(".purchase1").val(cartConfig[motorcycle1].purchaseMoney);
//console.log(a);
}

28.json數組,select選擇,input輸出對應數據