简体   繁体   English

如何基于上一个选择列表的选择选项更改选择列表中的选项?

[英]How to change options in a select list, based on the selected option of a previous select list?

如何基于上一个选择列表的选择选项更改选择列表中的选项?

试试这个脚踏板。

you cant do dynamic like this via simple html. 您无法通过简单的html进行动态处理。 You should use javascript for example. 您应该使用javascript为例。 In google there are a lot of solutions, this is one of them: http://programmersforum.ru/showpost.php?p=227550&postcount=3 在Google中,有很多解决方案,这是其中一种: http : //programmersforum.ru/showpost.php?p=227550&postcount=3

The easiest way to do this is to use jQuery . 最简单的方法是使用jQuery

For example: 例如:

var categoryItems = {
    'Car':             [ 'Acura', 'Honda', 'Toyota' ],
    'Computer:         [ 'Dell', 'HP', 'Lenovo' ],
    'Search engine':   [ 'Google', 'Bing', 'Yahoo' ]
};
$('#category').change(function() {
    var itemsDropdown = $('#items').empty();
    var items = categoryItems[$(this).val()];
    for(var i = 0;  < items.length; i++)
        itemsDropdown.append($('<option />').text(items[i]));
});

暂无
暂无

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

相关问题 根据另一个选定的选项更改 select 选项 - Change select options based on another selected option 根据所选选项更改同一选择中的选项 - Change options in same select based on selected option 3个选择元素,它们根据第一选择和第二选择中的所选选项更改选项 - 3 select elements that change options based on the selected option in the first and second select 为jQuery添加选定对象以基于第一个选择列表选项更改第二个选择列表 - Add selected for jQuery to change a second select list based on the first select list option jQuery如何根据“第三个选择列表”选项更改第二个选择列表,并根据第一个选择更改第二个选择列表 - How jQuery to change a second select list based on the Third select list option and second select based upon first 前一个选项列表中所选项目的动态选项 - dynamic options for selected item in previous option list 如何根据 jQuery 数据表中先前选择的值更新 select 选项 - how to update select options based on previous selected values in jQuery DataTables 如何根据 vue js 选择的另一个 select 选项更改选择选项 - how to change a selections options based on another select option selected by vue js 当值是动态的时,如何基于第一个选择列表选项更改第二个选择列表? - How to change a second select list based on the first select list option when values are dynamic? 如何通过 <option>在一个<select>列出功能,同时跟踪所选选项? - How to pass <option> in a <select> list into function whilst keeping track of selected options?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM