これが IE10 で機能しないのはなぜですか? Chrome、Firefox、Opera、Safari で正常に動作します。
HTML:
<form action="#">
<label for="NoOfRooms">Select number of rooms required</label>
<select id="NoOfRooms" onchange="showHide()">
<option value="1" selected="selected">1 room</option>
<option value="2">2 rooms</option>
<option value="3">3 rooms</option>
</select>
<br />
<label id="Room1TypeLabel" for="Room1Type" class="inline">Room 1:</label>
<select id="Room1Type">
<option value="1" selected="selected">Single</option>
<option value="2">Double</option>
<option value="3">Triple</option>
</select>
<br />
<label id="Room2TypeLabel" for="Room2Type" class="hidden">Room 2:</label>
<select id="Room2Type" class="hidden">
<option value="1">Single</option>
<option value="2" selected="selected">Double</option>
<option value="3">Triple</option>
</select>
<br />
<label id="Room3TypeLabel" for="Room1Type" class="hidden">Room 3:</label>
<select id="Room3Type" class="hidden">
<option value="1">Single</option>
<option value="2">Double</option>
<option value="3" selected="selected">Triple</option>
</select>
</form>
JavaScript:
function showHide() {
"use strict";
var NoOfRooms = document.getElementById("NoOfRooms");
var NoOfRoomsValue = NoOfRooms.options[NoOfRooms.selectedIndex].value;
if (NoOfRoomsValue == 2) {
Room2Type.style.display = "inline";
Room3Type.style.display = "none";
Room2TypeLabel.style.display = "inline";
Room3TypeLabel.style.display = "none";
} else if (NoOfRoomsValue == 3) {
Room2Type.style.display = "inline";
Room3Type.style.display = "inline";
Room2TypeLabel.style.display = "inline";
Room3TypeLabel.style.display = "inline";
} else if (NoOfRoomsValue == 1) {
Room2Type.style.display = "none";
Room3Type.style.display = "none";
Room2TypeLabel.style.display = "none";
Room3TypeLabel.style.display = "none";
} else alert("Error. Please try again.");
}
CSS:
.hidden {
display: none;
}
フィドル。