地址接口調用

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<script src="jq.js" type="text/javascript"></script>	
<script type="text/javascript"> 
$(function(){
getProvince();
$("#province").change(function(){

     var code=$(this).val();
      getCity(code);
 
 $("#city").change(function(){
 	var code=$(this).val();
 	getDisc(code);

 	$("#disc").change(function(){
 	var code=$(this).val();
 	getStreet(code);
 });
 });
 });
});

function getProvince(){
 $.get("http://www.hxyxt.com/yxtws/v1/hxyxt/account/getaccount",function(data){
 var $select = $('#province');  
for(var i=0; i<data.length;i++){  
  $select.append('<option value="'+data[i].isocode+'">'+data[i].name+'</option>'); 
} 

 });
}

function  getCity(code){
 $.get("http://www.hxyxt.com/yxtws/v1/hxyxt/account/select-address?cmd=provinceselected&value="+code,function(data){
 var $select = $('#city');
for(var i=0; i<data.length;i++){  
  $select.append('<option value="'+data[i].code+'">'+data[i].name+'</option>'); 
} 
});
}
function getDisc(code){

$.get("http://www.hxyxt.com/yxtws/v1/hxyxt/account/select-address?cmd=cityselected&value="+code,function(data){
	 var $select = $('#disc');
	 // console.log(data);
	 for(var i=0; i<data.length;i++){  
  $select.append('<option value="'+data[i].code+'">'+data[i].name+'</option>'); 
}
});
}
function getStreet(code){
$.get("http://www.hxyxt.com/yxtws/v1/hxyxt/account/select-address?cmd=districtselected&value="+code,function(data){
	 var $select = $('#street');

	 for(var i=0; i<data.length;i++){  
  $select.append('<option value="'+data[i].code+'">'+data[i].name+'</option>');
}
});
}
</script> 
<select id="province" name="province"> 
<option>----請選擇省份----</option>

</select>
<select id="city" name="city" > 
<option>----請選擇城市----</option>
</select>
<select id="disc" name="disc" > 
<option>----請選擇區或縣----</option>
</select>
<select id="street" name="street" > 
<option>----請選擇街道----</option>
</select>
</script>
</head>
<body>
</body>
</html>

圖案示例

相關文章
相關標籤/搜索