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
vertical-align attribute is mainly used to change...
Table of contents Preface 1. Binary Tree 1.1. Tra...
Table of contents Hidden, descending, and functio...
Set the table's style="table-layout:fixed...
1. Introduction As we all know, in the applicatio...
System performance expert Brendan D. Gregg update...
This article describes how to create multiple ins...
This article uses an example to illustrate the us...
This article shares the installation and configur...
"/" is the root directory, and "~&...
Knowledge point 1: Set the base URL of the web pa...
introduce This chapter mainly introduces the proc...
Introduction to Vue The current era of big front-...
The attributes of the <TD> tag are used to ...
What does Ctrl+c, Ctrl+d, Ctrl+z mean in Linux? C...