基本完成,有bug
This commit is contained in:
parent
c41689b828
commit
71d37fac5f
@ -13,10 +13,10 @@
|
|||||||
<div>
|
<div>
|
||||||
<form>
|
<form>
|
||||||
省份:
|
省份:
|
||||||
<select name="province" id="province" onchange="showCity()">
|
<select name="province" id="province">
|
||||||
<option value="0">--请选择--</option>
|
<option value="0">--请选择--</option>
|
||||||
</select> 城市:
|
</select> 城市:
|
||||||
<select name="city" id="city" onchange="showArea()">
|
<select name="city" id="city">
|
||||||
<option value="0">--请选择--</option>
|
<option value="0">--请选择--</option>
|
||||||
</select> 地区:
|
</select> 地区:
|
||||||
<select name="area" id="area">
|
<select name="area" id="area">
|
||||||
@ -28,6 +28,16 @@
|
|||||||
<script>
|
<script>
|
||||||
$(function(){
|
$(function(){
|
||||||
getCountry();
|
getCountry();
|
||||||
|
|
||||||
|
$("#province").change(function(){
|
||||||
|
CountryId=$("#province").val();
|
||||||
|
// console.log(FatherId);
|
||||||
|
getCity(CountryId);
|
||||||
|
CityID=$("#city").val();
|
||||||
|
console.log(CityID);
|
||||||
|
getArea(CityID);
|
||||||
|
});
|
||||||
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
@ -1,13 +1,32 @@
|
|||||||
function getCountry(code){
|
|
||||||
$.ajax({
|
function getData(){
|
||||||
url : './json/third-level-address.json',
|
$.ajax({
|
||||||
type : 'get',
|
url : './json/third-level-address.json',
|
||||||
async: false,
|
type : 'get',
|
||||||
success : function(data) {
|
async: false,
|
||||||
if(data=="error"){
|
success : function(data) {
|
||||||
alert("系统错误");
|
if(data=="error"){
|
||||||
return;
|
alert("系统错误");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
dataJson=data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return dataJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getCountry(){
|
||||||
|
// $.ajax({
|
||||||
|
// url : './json/third-level-address.json',
|
||||||
|
// type : 'get',
|
||||||
|
// async: false,
|
||||||
|
// success : function(data) {
|
||||||
|
// if(data=="error"){
|
||||||
|
// alert("系统错误");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
var data = getData();
|
||||||
var country = new Array();
|
var country = new Array();
|
||||||
var children = new Array();
|
var children = new Array();
|
||||||
var countryCode=new Array();
|
var countryCode=new Array();
|
||||||
@ -16,25 +35,38 @@ function getCountry(code){
|
|||||||
country.push(tmp.name);
|
country.push(tmp.name);
|
||||||
children.push(tmp.children);
|
children.push(tmp.children);
|
||||||
});
|
});
|
||||||
$('#country').show().html(country);
|
// for(var i in data){
|
||||||
// console.log(children);
|
// console.log(data[i].children[0].children[0].code);
|
||||||
|
// }
|
||||||
|
// console.log(data[0].children[1].name);
|
||||||
var options = "<option value='0'>--请选择--</option>";
|
var options = "<option value='0'>--请选择--</option>";
|
||||||
for(var i in data){
|
for(var i in data){
|
||||||
if(code && code == data[i].code ){
|
options += "<option value='" + data[i].code + "' selected>" + dataJson[i].name+"</option>";
|
||||||
options += "<option value='" + data[i].code + "' selected>" + dataJson[i].name+"</option>";
|
|
||||||
}else{
|
|
||||||
options += "<option value='" + data[i].code + "' >" + data[i].name+"</option>";
|
|
||||||
}
|
|
||||||
$("#province").html(options);
|
$("#province").html(options);
|
||||||
// console.log(data[i].code);
|
// console.log(data[i].code);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
error : function(data) {
|
|
||||||
html = "<option value='0'>--请选择--</option>";
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function showCity(){
|
function getCity(countryCode){
|
||||||
|
var data = getData();
|
||||||
|
$('#city').empty();
|
||||||
|
var options = "<option value='0'>--请选择--</option>";
|
||||||
|
for(var i in data){
|
||||||
|
if(countryCode && countryCode == data[i].code){
|
||||||
|
options += "<option value='" + data[i].children[0].code + "' selected>" + data[i].children[0].name+"</option>";
|
||||||
|
}
|
||||||
|
$("#city").html(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
function getArea(cityCode){
|
||||||
|
var data = getData();
|
||||||
|
var options = "<option value='0'>--请选择--</option>";
|
||||||
|
for(var i in data){
|
||||||
|
if(cityCode && cityCode == data[i].children[0].code){
|
||||||
|
options += "<option value='" + data[i].children[0].children[0].code + "' selected>" + data[i].children[0].children[0].name+"</option>";
|
||||||
|
}
|
||||||
|
$("#area").html(options);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user