简体   繁体   English

改变<select>javascript的动态选项

[英]Change <select> options with javascript dynamically

Can I use a javascript if/else function to change the select options of a form?我可以使用javascript if / else函数来更改表单的选择选项吗? I don't want to use CSS to hide/display different dropdown menus, so here is what I've ccome up with:我不想使用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; }
 <input type="text" id="food"> <select id="pickone"> <option id="1"></option> <option id="2"></option> </select>

I can't seem to find any documentation about how to do this, so any help would be great.我似乎找不到有关如何执行此操作的任何文档,因此任何帮助都将非常有用。

Can I use a javascript if/else function to change the select options of a form?我可以使用javascript if / else函数来更改表单的选择选项吗? I don't want to use CSS to hide/display different dropdown menus, so here is what I've ccome up with:我不想使用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; }
 <input type="text" id="food"> <select id="pickone"> <option id="1"></option> <option id="2"></option> </select>

I can't seem to find any documentation about how to do this, so any help would be great.我似乎找不到有关如何执行此操作的任何文档,因此任何帮助都将非常有用。

Can I use a javascript if/else function to change the select options of a form?我可以使用javascript if / else函数来更改表单的选择选项吗? I don't want to use CSS to hide/display different dropdown menus, so here is what I've ccome up with:我不想使用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; }
 <input type="text" id="food"> <select id="pickone"> <option id="1"></option> <option id="2"></option> </select>

I can't seem to find any documentation about how to do this, so any help would be great.我似乎找不到有关如何执行此操作的任何文档,因此任何帮助都将非常有用。

Can I use a javascript if/else function to change the select options of a form?我可以使用javascript if / else函数来更改表单的选择选项吗? I don't want to use CSS to hide/display different dropdown menus, so here is what I've ccome up with:我不想使用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; }
 <input type="text" id="food"> <select id="pickone"> <option id="1"></option> <option id="2"></option> </select>

I can't seem to find any documentation about how to do this, so any help would be great.我似乎找不到有关如何执行此操作的任何文档,因此任何帮助都将非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM