我可以使用 javascript if/else 函数来更改表单的选择选项吗?我不想使用 CSS 来隐藏/显示不同的下拉菜单,所以这是我想出的:
function getType() {
var x = document.getElementById("food").value;
var items;
if (x === "fruit") {
items = "Apple" || items = "Oranges" || items = "Bananas";
else {
items = "Eggplants" || items = "Olives"
}
document.getElementById("pickone").value;
}
Run Code Online (Sandbox Code Playgroud)
<input type="text" id="food">
<select id="pickone">
<option id="1"></option>
<option id="2"></option>
</select>Run Code Online (Sandbox Code Playgroud)
我似乎找不到任何有关如何执行此操作的文档,因此任何帮助都会很棒。