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:
|
<<: How to monitor and delete timed out sessions in Tomcat
>>: One sql statement completes MySQL deduplication and keeps one
There is a question that has troubled web designe...
Database performance optimization generally adopt...
In the case of concurrent access, non-repeatable ...
Download tutorial of mysql-connector-java.jar pac...
Three-way handshake phase Number of retries for c...
Global Object All modules can be called global: r...
In actual projects, the up and down scroll bars a...
Table of contents Preface text 1. Panel 2. Huaron...
Install MySQL database a) Download the MySQL sour...
1. Introduction Supervisor is a general process m...
This article records the installation and configu...
CSS to achieve the image hovering mouse folding e...
Ubuntu's own source is from China, so the dow...
Table of contents 1. Introduction 2. GitHub 3. Ba...
Table of contents background How does element-ui&...