js implements simple provincial, municipal and district three-level selection cascade

js implements simple provincial, municipal and district three-level selection cascade

This article shares the specific code of js to realize the three-level selection of provinces, cities and districts for your reference. The specific content is as follows

Code:

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Title</title>
 </head>
 <body>
      <select id="province">
        <option>---Please select---</option>
      </select>
      <select id="city">
        <option>---Please select---</option>
      </select>
      <select id="area">
        <option>---Please select---</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>"+"---Please select---"+"</option>");
                    $("#area").html("<option>"+"---Please select---"+"</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>"+"---Please select---"+"</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>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • A complete example of a national provincial and municipal secondary linkage drop-down selection menu implemented by js
  • PHP+Mysql+Ajax+JS realizes the linkage between provinces, cities and districts
  • JS makes a simple three-level linkage
  • Select cascading drop-down box example in Vue.js 2.0
  • The best provincial and municipal secondary linkage native js to achieve what you deserve
  • JS real multi-level linkage drop-down menu class, easily realize the linkage menu of provinces, cities and districts!
  • JavaScript realizes the three-level linkage drop-down box menu of provinces, cities and districts
  • Province, city and district three-level linkage drop-down box menu javascript version
  • jquery+json universal three-level linkage drop-down list
  • js to achieve the effect code of cascading drop-down menu of provinces and cities across the country

<<:  How to monitor and delete timed out sessions in Tomcat

>>:  One sql statement completes MySQL deduplication and keeps one

Recommend

CentOS6 upgrade glibc operation steps

Table of contents background Compile glibc 2.14 M...

How to configure Linux CentOS to run scripts regularly

Many times we want the server to run a script reg...

Detailed explanation of Vue data proxy

Table of contents 1. What I am going to talk abou...

Vue implements multi-column layout drag

This article shares the specific code of Vue to i...

How to place large images in a small space on a web page

Original source: www.bamagazine.com There are nar...

Nginx http health check configuration process analysis

Passive Check With passive health checks, NGINX a...

Implementation of HTML command line interface

HTML Part Copy code The code is as follows: <!D...

Implementation of React page turner (including front and back ends)

Table of contents front end According to the abov...

How to build php+nginx+swoole+mysql+redis environment with docker

Operating system: Alibaba Cloud ESC instance cent...

Nginx monitoring issues under Linux

nginx installation Ensure that the virtual machin...

Several ways to use v-bind binding with Class and Style in Vue

Adding/removing classes to elements is a very com...

Detailed explanation of MySQL execution plan

The EXPLAIN statement provides information about ...