格式化代码
This commit is contained in:
@@ -1,69 +1,57 @@
|
||||
|
||||
function getData(){
|
||||
function getData() {
|
||||
$.ajax({
|
||||
url : './json/third-level-address.json',
|
||||
type : 'get',
|
||||
url: './json/third-level-address.json',
|
||||
type: 'get',
|
||||
async: false,
|
||||
success : function(data) {
|
||||
if(data=="error"){
|
||||
alert("系统错误");
|
||||
return;
|
||||
success: function (data) {
|
||||
if (data == "error") {
|
||||
alert("系统错误");
|
||||
return;
|
||||
}
|
||||
dataJson = data;
|
||||
}
|
||||
dataJson=data;
|
||||
}
|
||||
});
|
||||
return dataJson;
|
||||
}
|
||||
|
||||
|
||||
function getCountry(){
|
||||
var data = getData();
|
||||
var country = new Array();
|
||||
var children = new Array();
|
||||
var countryCode=new Array();
|
||||
$.each(data,function(i,tmp){
|
||||
countryCode.push(tmp.code);
|
||||
country.push(tmp.name);
|
||||
children.push(tmp.children);
|
||||
});
|
||||
// for(var i in data){
|
||||
// console.log(data[i].children[0].children.length);
|
||||
// }
|
||||
var options = "<option value='0'>--请选择--</option>";
|
||||
for(var i in data){
|
||||
options += "<option value='" + data[i].code + "' selected>" + dataJson[i].name+"</option>";
|
||||
$("#province").html(options);
|
||||
// console.log(data[i].code);
|
||||
}
|
||||
}
|
||||
function getCountry() {
|
||||
var data = getData();
|
||||
var options = "<option value='0'>--请选择--</option>";
|
||||
for (var i in data) {
|
||||
options += "<option value='" + data[i].code + "' selected>" + data[i].name + "</option>";
|
||||
$("#province").html(options);
|
||||
}
|
||||
}
|
||||
|
||||
function getCity(countryCode){
|
||||
function getCity(countryCode) {
|
||||
var data = getData();
|
||||
$('#city').empty();
|
||||
var options = "<option value='0'>--请选择--</option>";
|
||||
for(var i in data){
|
||||
for(let j=0;j<data[i].children.length;j++){
|
||||
if(countryCode && countryCode == data[i].code){
|
||||
options += "<option value='" + data[i].children[j].code + "' selected>" + data[i].children[j].name+"</option>";
|
||||
}
|
||||
|
||||
}
|
||||
$("#city").html(options);
|
||||
}
|
||||
|
||||
for (var i in data) {
|
||||
for (let j = 0; j < data[i].children.length; j++) {
|
||||
if (countryCode && countryCode == data[i].code) {
|
||||
options += "<option value='" + data[i].children[j].code + "' selected>" + data[i].children[j].name + "</option>";
|
||||
}
|
||||
|
||||
}
|
||||
$("#city").html(options);
|
||||
}
|
||||
|
||||
}
|
||||
function getArea(cityCode){
|
||||
|
||||
function getArea(cityCode) {
|
||||
var data = getData();
|
||||
var options = "<option value='0'>--请选择--</option>";
|
||||
for(var i in data){
|
||||
for(let j=0;j<data[i].children.length;j++){
|
||||
for(let k=0;k<data[i].children[j].children.length;k++){
|
||||
if(cityCode && cityCode == data[i].children[j].code){
|
||||
options += "<option value='" + data[i].children[j].children[k].code + "' selected>" + data[i].children[j].children[k].name+"</option>";
|
||||
for (var i in data) {
|
||||
for (let j = 0; j < data[i].children.length; j++) {
|
||||
for (let k = 0; k < data[i].children[j].children.length; k++) {
|
||||
if (cityCode && cityCode == data[i].children[j].code) {
|
||||
options += "<option value='" + data[i].children[j].children[k].code + "' selected>" + data[i].children[j].children[k].name + "</option>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$("#area").html(options);
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user