效果:选择对应的车类,下面的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);
}
原文地址:https://www.cnblogs.com/sqyambition/p/8503494.html