亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

使用jquery怎么實現戶籍地選擇下拉框

發布時間:2021-06-01 16:07:18 來源:億速云 閱讀:122 作者:Leah 欄目:開發技術

今天就跟大家聊聊有關使用jquery怎么實現戶籍地選擇下拉框,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。

data.js

var data = [{
        provname: '浙江省',
        provId: 1,
        citys: [{
            cityname: "杭州市",
            cityId: 101,
            areas: [{
                    areaname: "杭州一區",
                    areaId: 1011
                },
                {
                    areaname: "杭州二區",
                    areaId: 1012
                }
            ]
        }, {
            cityname: "溫州市",
            cityId: 102,
            areas: [{
                areaname: '溫州一區',
                areaId: 1021
            }, {
                areaname: '溫州二區',
                areaId: 1022
            }]
        }, {
            cityname: "寧波市",
            cityId: 103,
            areas: [{
                areaname: '寧波一區',
                areaId: 1031
            }, {
                areaname: '寧波二區',
                areaId: 1032
            }]

        }, {
            cityname: "紹興市",
            cityId: 104,
            areas: [{
                areaname: '紹興一區',
                areaId: 1041
            }, {
                areaname: '紹興二區',
                areaId: 1042
            }]

        }]
    }, {
        provname: '山東省',
        provId: 2,
        citys: [{
            cityname: "濟南市",
            cityId: 201,
            areas: [{
                    areaname: "濟南一區",
                    areaId: 2011
                },
                {
                    areaname: "濟南二區",
                    areaId: 2012
                }
            ]
        }, {
            cityname: "青島市",
            cityId: 202,
            areas: [{
                areaname: '青島一區',
                areaId: 2021
            }, {
                areaname: '青島二區',
                areaId: 2022
            }]
        }, {
            cityname: "濟寧市",
            cityId: 203,
            areas: [{
                areaname: '濟寧一區',
                areaId: 2031
            }, {
                areaname: '濟寧二區',
                areaId: 2032
            }]

        }, {
            cityname: "濰坊市",
            cityId: 204,
            areas: [{
                areaname: '濰坊一區',
                areaId: 2041
            }, {
                areaname: '濰坊二區',
                areaId: 2042
            }]

        }]
    },
    {
        provname: '廣東省',
        provId: 3,
        citys: [{
            cityname: "廣州市",
            cityId: 301,
            areas: [{
                    areaname: "廣州一區",
                    areaId: 3011
                },
                {
                    areaname: "廣州二區",
                    areaId: 3012
                }
            ]
        }, {
            cityname: "潮陽市",
            cityId: 302,
            areas: [{
                areaname: '潮陽一區',
                areaId: 3021
            }, {
                areaname: '潮陽二區',
                areaId: 3022
            }]
        }, {
            cityname: "澄海市",
            cityId: 303,
            areas: [{
                areaname: '澄海一區',
                areaId: 3031
            }, {
                areaname: '澄海二區',
                areaId: 3032
            }]

        }, {
            cityname: "潮州市",
            cityId: 304,
            areas: [{
                areaname: '潮州一區',
                areaId: 3041
            }, {
                areaname: '潮州二區',
                areaId: 3042
            }]

        }]
    },
    {
        provname: '甘肅省',
        provId: 4,
        citys: [{
            cityname: "蘭州市",
            cityId: 401,
            areas: [{
                    areaname: "蘭州一區",
                    areaId: 4011
                },
                {
                    areaname: "蘭州二區",
                    areaId: 4012
                }
            ]
        }, {
            cityname: "白銀市",
            cityId: 402,
            areas: [{
                areaname: '白銀一區',
                areaId: 4021
            }, {
                areaname: '白銀二區',
                areaId: 4022
            }]
        }, {
            cityname: "敦煌市",
            cityId: 403,
            areas: [{
                areaname: '敦煌一區',
                areaId: 4031
            }, {
                areaname: '敦煌二區',
                areaId: 4032
            }]

        }, {
            cityname: "定西市",
            cityId: 404,
            areas: [{
                areaname: '定西一區',
                areaId: 4041
            }, {
                areaname: '定西二區',
                areaId: 4042
            }]

        }]
    }
]

demo.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/jquery.min.js"></script>
    <script src="js/data.js"></script>
</head>
<body>
    <!-- 先添加三個下拉列表 -->
    <select name="prov" id="prov">

    </select>
    <select name="city" id="city">

    </select>
    <select name="area" id="area">
        
    </select>
    
    <script>
        var $prov=$("#prov")
        var $city=$("#city")
        var $area=$("#area")

        $(function(){
            //頁面加載完成后觸發
            $.each(data,function(i,e){
                $prov.append('<option value="'+e.provId+'">'+e.provname+'</option>')   //在$obj的末尾追加子元素newObj

            })
            $prov.prepend('<option value=""  selected>請選擇</option>');
            //當省名被選擇時,觸發以下事件
            $prov.on("change",function(){
                //遍歷省
                $.each(data,function(i,e){
                    if($prov.val()==e.provId){  
                        //遍歷市
                        $city.html('<option value="">請選擇</option>');//用來清空之前選擇的市
                        $.each(e.citys,function(i,e2){
                            $city.append('<option value="'+e2.cityId+'">'+e2.cityname+'</option>');
                        })
                            
                    }

                })
            })

            //當市名被選擇時,觸發以下事件
            $city.on("change",function(){
                //遍歷省
                $.each(data,function(i,e){
                    if($prov.val()==e.provId){
                        $.each(e.citys,function(i,e2){
                            if($city.val()==e2.cityId){
                                $area.html('<option value="">請選擇</option>');
                                $.each(e2.areas,function(i,e3){
                                    $area.append('<option value="'+e3.areaId+'">'+e3.areaname+'</option>');
                                })
                            }
                        })
                    }
                })
                    
            })
            

        })
        

    </script>
</body>
</html>

看完上述內容,你們對使用jquery怎么實現戶籍地選擇下拉框有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

保定市| 隆安县| 绵阳市| 鲁山县| 夏津县| 大宁县| 湟中县| 茂名市| 晋州市| 汉川市| 保亭| 溧水县| 白水县| 顺平县| 远安县| 屯留县| 启东市| 剑川县| 娱乐| 永修县| 简阳市| 皮山县| 莎车县| 长阳| 富源县| 海晏县| 荣昌县| 蒙阴县| 绥宁县| 沙河市| 咸阳市| 南安市| 平安县| 墨脱县| 沛县| 万山特区| 长沙县| 马公市| 襄汾县| 桂林市| 商丘市|