开发者

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

开发者 https://www.devze.com 2022-12-21 18:31 出处:网络
H开发者_JAVA技巧ow to change options in a select list, based on the selected option of a previous select list?Try this tread.you cant do dynamic like this via simple html. You should use javascript fo

H开发者_JAVA技巧ow to change options in a select list, based on the selected option of a previous select list?


Try this tread.


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]));
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号