how to implement a dynamic combo box selection system

前端 未结 3 938
太阳男子
太阳男子 2020-12-17 06:20

I\'m implementing a system these days, i want to implement a combo box selection process but i don\'t know how to implement it, so asking you guys favor?

my scenario

3条回答
  •  甜味超标
    2020-12-17 06:48

    The trick is do subscribe to the change event and reset the contents of the second box accordingly.

    HTML:

     
    
     
    

    JavaScript (on ready):

    var selectBrand = $("#brand");
    var selectType = $("#type");
    
    var optionsList = {
        nokia: [
            "C6-01",
            "E7-00"
        ],
        apple: [
            "iPhone 3",
            "iPhone 3G",
            "iPhone 4"
        ]
    };
    
    selectBrand.change(function() {
        var brand = selectBrand.val();
        var options = optionsList[brand];
        var html;
    
        if (options) {
            html = '';
            $.each(options, function(index, value) {
                html += '';
            });
        } else {
            html = '';
        }
        selectType.html(html);
    }).change();
    

    Full example at See http://www.jsfiddle.net/TJJ8f/

提交回复
热议问题