2 回答
TA贡献1788条经验 获得超4个赞
让我告诉你。在 if-else 语句中,您不是在比较值,而是实际上是在分配值。
因此,将 if-else 语句更改为:
if(selectedStand == "platinumGallery"){
costOfTicket = 25000;
}
else if(selectedStand == "superHospitalityStand"){
costOfTicket = 20000;
}
TA贡献1719条经验 获得超6个赞
您在声明=中使用了if。您需要在`if 语句中使用==or===来使其作为条件起作用。
function myFun2(){
var costOfTicket;
var selectedStand = document.getElementById("stand").value;
if(selectedStand == "platinumGallery"){
costOfTicket = 25000;
}
else if(selectedStand == "superHospitalityStand"){
costOfTicket = 20000;
}
document.getElementById("costOfTicket").value = costOfTicket;
}
<select id="stand" onchange="myFun2()">
<option value="platinumGallery">Platinum Gallery</option>
<option value="superHospitalityStand">Super Hospitality Stand</option>
<option value="northWestStand">North West Stand</option>
<option value="eastStand">East Stand</option>
</select><br><br>
<label>Cost Of Ticket: </label>
<input id="costOfTicket" type="text" readonly>
添加回答
举报