js)select 2級メニュー

2034 ワード




    
    select      


    var cityArr = [];
    cityArr['   '] =
            [
                {txt:'  ', val:'  '},
                {txt:'  ', val:'  '},
                {txt:'  ', val:'  '},
                {txt:'  ', val:'  '},
                {txt:'  ', val:'  '},
                {txt:'  ', val:'  '},
                {txt:'  ', val:'  '},
                {txt:'  ', val:'  '},
                {txt:'  ', val:'  '}
            ];
    cityArr['   '] =
            [
                {txt:'  ', val:'  '},
                {txt:'  ', val:'  '},
                {txt:'  ', val:'  '},
                {txt:'  ', val:'  '}
            ];

    function setSelectOption(selectObj, optionList, firstOption, selected) {

    }

    function setCity(province) {
        console.log(province);
        //setSelectOption('city', cityArr[province], '-   -');
        var city = document.getElementById('city');
        var city_len = city.options.length;
        console.log(city_len);
        for(var i = 0; i < city_len; i++) {
            if(city_len > 0) {
                city.options.remove(0);
            }
        }

        if(province == "0") {
            var opt = new Option('-   -', 0);
            city.options.add(opt);
        }
        else {
            var province_len = cityArr[province].length;
            for(i = 0;i< province_len; i++) {
                var opt = new Option(cityArr[province][i].txt, cityArr[province][i].val);
                city.options.add(opt);
            }
        }
    }


  
転載先:https://www.cnblogs.com/yll-sww/p/4754504.html