<!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>
转载于:https://my.oschina.net/u/2953372/blog/801392