3단계 연동 - jQuery

2710 단어



    
         -jQuery 
    


    
    
    
    
        var arrProvince = ["   ","  ","  ","  ","  "];  //  
        var arrCity = [     //  
            ["    ","     ","    "],
            ["   ","   ","   "],
            ["   ","   ","   "],
            ["   ","   ","    "],
            ["   ","   ","   "]
        ];
        var arrCounty = [   //   
            [
                ["   ","   ","   "],
                ["    ","   ","   ","   "],
                ["   ","   ","   ","   "]
            ],[
                ["   ","   ","   ","   "],
                ["    ","   ","    "],
                ["   ","   ","   ","   "]
            ],[
                ["   ","  ","  "],
                ["   ","   ","   ","   "],
                ["   ","       ","       "]
            ],[
                ["   ","   ","   ","   "],
                ["   ","   ","   "],
                ["   ","   ","   "]
            ],[
                ["   ","   ","   "],
                ["   ","   ","   ","   "],
                ["  ","  ","  ","  "]
            ]
        ];
        for( var i = 0; i < arrProvince.length; i++ ){
            $("#province").append("<option value=" + i + ">" + arrProvince[i] + "</option>");
        };
        $("#province").change(function(){
            //                    1;         
            $("#city")[0].length = 1;
            //             (           )
            var $indexProvince = $(":selected").val();
            var $city = arrCity[$indexProvince];
            for (var j = 0; j< $city.length ; j++) {
                $("#city").append("<option value=" + $indexProvince + "_" + j + ">"+$city[j]+"</option>");
            };
        });
        $("#city").change(function(){
            //                    1;         
            $("#county")[0].length = 1;
            var str = $("#city :selected").val();
            var arr = str.split("_");
            var $provincIndex = arr[0];
            var $cityIndex = arr[1];
            var $county = arrCounty[$provincIndex][$cityIndex];
            for( var k = 0; k < $county.length; k++ ){
                $("#county").append("<option>" + $county[k] + "</option>")
            };
        });
    


좋은 웹페이지 즐겨찾기