简体   繁体   中英

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. You should use javascript for example. In google there are a lot of solutions, this is one of them: http://programmersforum.ru/showpost.php?p=227550&postcount=3

The easiest way to do this is to use 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]));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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