IE10에서이 기능이 작동하지 않는 이유는 무엇입니까? Chrome, Firefox, Opera 및 Safari에서 잘 작동합니다.IE에서이 JavaScript 코드가 작동하지 않는 이유는 무엇입니까?
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>
자바 스크립트 :
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;
}
그래, Chrome에서는 작동하지 않습니다. – Tim
어떻게해야할까요? – jahroy
당신은'option' 요소를 숨길 수 없습니다. 추가/제거 만 가능합니다. – Eru