I searched for three-level linkage on the Internet and found that they were all written in option. I suddenly had an idea to write one in other ways. I feel that the effect is not bad. If you are interested, you can take a look. Without further ado, let's see the effect The code is as follows. It's a bit messy. If you want to see it, just take a look. 1.html code <div class="box"> <section class="province">Province</section> <section class="city">City</section> <section class="area">Area</section> <div class="si"> </div> </div> 2.css code <style> .box{ width: 800px; height: 50px; margin: 20px auto; background-color: rgb(48, 49, 48); border-radius: 10px; display: flex; justify-content: center; align-items: center; } .box section{ display: inline-block; background-color: rgb(168, 165, 165); flex-grow: 1; height: 30px; margin-right: 10px; margin-left: 10px; border-radius: 5px; line-height: 30px; padding-left: 10px; } .box section:hover{ cursor: pointer; } .si{ display: none; } .box .all{ display: block; width: 740px; background-color: rgb(211, 203, 203); padding: 20px; position: absolute; border-radius: 10px; top: 57px; } .box .all:hover{ cursor: pointer; } .box .all span{ display: inline-block; width: 130px; height: 30px; font-size: 13px; padding-left: 10px; line-height: 30px; border-radius: 5px; margin-left: 10px; border: 1px solid #000; background-color: white; box-sizing: border-box; margin-top: 10px; } </style> 3.js code <script> // Get content var data = city_code // This is my data // Get province, city, district var province = document.querySelector(".province") var city = document.querySelector(".city") var area = document.querySelector(".area") // Get the hidden div var si = document.querySelector(".si") province.addEventListener("mouseover",function(){ si.classList.add("all") // Select the province var html = "" var all = document.querySelector(".all") for(var i = 0;i<data.length;i++){ const provinceName = data[i].name const provinceID = data[i].code html += `<span id="${provinceID}">${provinceName}</span>` } all.innerHTML=html var spanAll = document.querySelectorAll("span") for(var j =0;j<spanAll.length;j++){ spanAll[j].addEventListener("click",function(){ province.innerHTML=this.innerText province.id=this.id html = "" // Select a city for(var k = 0;k<data.length;k++){ if (data[k].code===province.id) { var citys = data[k].city for(var i = 0;i<citys.length;i++){ html +=`<span id="${citys[i].code}">${citys[i].name}</span>` } all.innerHTML=html var spanAll = document.querySelectorAll("span") for(var j =0;j<spanAll.length;j++){ spanAll[j].addEventListener("click",function(){ city.innerHTML=this.innerText city.id=this.id html = "" //Select area for(var k = 0; k<citys.length; k++){ if (citys[k].code===city.id) { var areas = cities[k].area for(var i = 0;i<areas.length;i++){ html +=`<span id="${areas[i].code}">${areas[i].name}</span>` } all.innerHTML=html var spanAll = document.querySelectorAll("span") for(var j =0;j<spanAll.length;j++){ spanAll[j].addEventListener("click",function(){ area.innerHTML = this.innerText area.id=this.id si.classList.remove("all") }) } break } } }) } break } } }) } }) </script> 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:
|
<<: Summary of several situations in which MySQL indexes fail
>>: How to configure Tomcat and run your first Java Web project on IntelliJ IDEA 2018
Today at work, a friend I added temporarily asked ...
Table of contents background What is the Metavers...
Table of contents MySQL delete syntax alias probl...
[Who is nslookup?] 】 The nslookup command is a ve...
Linux uses files as the basis to manage the devic...
Table of contents 1. Install the proxy module 2. ...
An event is an action performed by the user or th...
Table of contents How to display SQL log? ? Descr...
Table of contents 1. Variables Use meaningful nam...
The meaning of key_len In MySQL, you can use expl...
Table of contents 1. Installation and introductio...
Many times, after we install a web service applic...
Open any web page: for example, http://www.baidu....
Table of contents 1. Configure Linux hostname Con...
Web front end 1 Student ID Name gender age 01 Zha...