From 381fefa889edfb0b6369f2b87b1b568e18fbccbf Mon Sep 17 00:00:00 2001 From: Qing Date: Mon, 1 May 2023 21:47:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90,bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index.html | 8 ++++- .../js/index.js | 31 +++++++++---------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Html-practice/Ajax/基于jQuery的AJAX实现三级联动菜单/index.html b/Html-practice/Ajax/基于jQuery的AJAX实现三级联动菜单/index.html index c92cf06..4a52a95 100644 --- a/Html-practice/Ajax/基于jQuery的AJAX实现三级联动菜单/index.html +++ b/Html-practice/Ajax/基于jQuery的AJAX实现三级联动菜单/index.html @@ -34,9 +34,15 @@ // console.log(FatherId); getCity(CountryId); CityID=$("#city").val(); - console.log(CityID); + // console.log(CityID); getArea(CityID); + }); + $("#city").change(function(){ + CityID=$("#city").val(); + // console.log(CityID); + getArea(CityID); + }) }) diff --git a/Html-practice/Ajax/基于jQuery的AJAX实现三级联动菜单/js/index.js b/Html-practice/Ajax/基于jQuery的AJAX实现三级联动菜单/js/index.js index 90bda0b..f421c5f 100644 --- a/Html-practice/Ajax/基于jQuery的AJAX实现三级联动菜单/js/index.js +++ b/Html-practice/Ajax/基于jQuery的AJAX实现三级联动菜单/js/index.js @@ -16,16 +16,7 @@ function getData(){ } -function getCountry(){ - // $.ajax({ - // url : './json/third-level-address.json', - // type : 'get', - // async: false, - // success : function(data) { - // if(data=="error"){ - // alert("系统错误"); - // return; - // } +function getCountry(){ var data = getData(); var country = new Array(); var children = new Array(); @@ -36,9 +27,8 @@ function getCountry(){ children.push(tmp.children); }); // for(var i in data){ - // console.log(data[i].children[0].children[0].code); + // console.log(data[i].children[0].children.length); // } - // console.log(data[0].children[1].name); var options = ""; for(var i in data){ options += ""; @@ -52,9 +42,12 @@ function getCity(countryCode){ $('#city').empty(); var options = ""; for(var i in data){ - if(countryCode && countryCode == data[i].code){ - options += ""; + for(let j=0;j" + data[i].children[j].name+""; } + + } $("#city").html(options); } @@ -63,9 +56,13 @@ function getArea(cityCode){ var data = getData(); var options = ""; for(var i in data){ - if(cityCode && cityCode == data[i].children[0].code){ - options += ""; - } + for(let j=0;j" + data[i].children[j].children[k].name+""; + } + } +} $("#area").html(options); }