我有一个包含多个选项的选择表单。我还有一个 div,我只想在选择特定选项时显示它。你们能指出我正确的方向吗?最简单的方法是什么?
谢谢你:)
最佳答案
这是一个简单的非 jQuery 解决方案
window.onload=function() {
var sel = document.getElementById("sel1");
sel.onchange=function() {
document.getElementById("otherDiv").style.display=(this.value=="other")?"":"none";
}
sel.onchange(); // set the visibility onload too in case of reload
}
<select id="sel1">
.
.
.
<option value="other">Other</option>
</select>
<div id="otherDiv">Other options</div>
关于javascript - 如何在用户进行选择时切换可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6588640/