欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js實現(xiàn)簡單省市區(qū)三級選擇聯(lián)級

 更新時間:2021年04月27日 10:06:01   作者:魏郴  
這篇文章主要介紹了js實現(xiàn)簡單省市區(qū)三級選擇聯(lián)級,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了js實現(xiàn)省市區(qū)三級選擇聯(lián)級的具體代碼,供大家參考,具體內(nèi)容如下

代碼:

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Title</title>
 </head>
 <body>
      <select id="province">
        <option>---請選擇---</option>
      </select>
      <select id="city">
        <option>---請選擇---</option>
      </select>
      <select id="area">
        <option>---請選擇---</option>
      </select>
  <script src="addr.js"></script>
  <script src="../lib/jquery-3.3.1.js"></script>
  <script>
   var pro = [];
   $(function (){
                $.each(temp,function (){
                    $("#province").append("<option>"+$(this)[0].label+"</option>");
                });
                $("#province").on("change",function (){
                    $("#city").html("<option>"+"---請選擇---"+"</option>");
                    $("#area").html("<option>"+"---請選擇---"+"</option>")
                    var select_pro = $(this).val();
                    $.each(temp,function (index,element){
                        if (element.label == select_pro){
                            var city = element.children;
                            for (let i = 0; i < city.length ; i++) {
                                $("#city").append("<option>"+city[i].label+"</option>");
                            }
                            $("#city").on('change',function ()
                            {
                        $("#area").html("<option>"+"---請選擇---"+"</option>");
                         var select_city = $(this).val();

                        for (var i=0;i < city.length ; i++)
                            {
                             console.log(city[i].label);
                             if (city[i].label == select_city)
                             {
                               var area = city[i].children;
                               for (var i=0;i < area.length ; i++)
                                {
                          $("#area").append("<option>"+area[i].label+"</option>");
                                 }
                           }
                         }
                         });
                   }
               });
        });
   });
  </script>
 </body>
</html>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論