这是我的代码。请善意帮助我,因为我没有任何基本的Javascript编程。如果用户不从第一个下拉列表中选择OTHERS,则第二个元素和按钮不会出现。然后,选择无法提交,因为按钮没有出现。如果用户从第一个下拉列表中选择OTHERS,第二个元素和按钮将出现或可见。这是什么造成的?第一个元素在第一个调试时没有同时出现第二个元素
<html>
<head>
<title></title>
<script>
function checkchange() {
if (document.getElementById('favouritecolour').value == 'OTHERS') {
document.getElementById('other').style.display='block';
} else {
document.getElementById('other').style.display='none';
}
};
function check() {
if (document.getElementById('pets').value == 'OTHERS') {
document.getElementById('besides').style.display='block';
} else {
document.getElementById('besides').style.display='none';
}
};
</script>
</head>
<body>
<select id='favouritecolour' onChange='checkchange()'>
<option value='BLUE'>BLUE</option>
<option value='RED'>RED</option>
<option value='OTHERS'>OTHERS</option>
</select>
<div id='other' style="display: none">
<input type='text' placeholder="FILL IN"/><br/>
<select id='pets' onChange='check()'>
<option value='DOG'>DOG</option>
<option value='RABBIT'>RABBIT</option>
<option value='OTHERS'>OTHERS</option>
</select>
<div id='besides' style="display: none">
<input type='text' placeholder="FILL IN"/>
<input type="submit" name="SUBMIT" />
</div>
</body>
</html>
埃姆...我不太得到什么是你的问题?我试过这个,它似乎在工作? –
它正在工作。但我希望在第一次运行时出现下拉和按钮元素,或者调试代码。它似乎一个一个可见。 –