1.mysql数据文件导入,该文件会上传到我的资源库 dh_areas
2.HTML
<select id="province" name="province" οnchange="selcity(this.value,this.id)">
<option value="">请选择</option>
<volist name="province" id="vo" >
<option value="{$vo.area_id}">{$vo.area_name}</option>
</volist>
</select>
<select id="city" name="city" οnchange="selcity(this.value,this.id)">
<option value="">请选择</option>
</select>
<select id="country" name="country">
<option value="">请选择</option>
</select>
3.ajax
var selcityUrl="__APP__/Home/RegisterInfo/getArea";
function selcity(areaId,obgId){
$.ajax({
type:"post",
url:selcityUrl,
async:false,
data:{
"areaId":areaId
},
success:function(json){
var json = eval('(' + json + ')');
if(obgId=="province"){
$("#city").empty();
var optionObg="<option value=''>请选择</option>";
for (var i=0;i<json.count;i++) {
optionObg+="<option value='"+json[i].area_id+"'>"+json[i].area_name+"</option>";
}
$("#city").append(optionObg);
}else{
$("#country").empty();
var optionObg="<option value=''>请选择</option>";
for (var i=0;i<json.count;i++) {
optionObg+="<option value='"+json[i].area_id+"'>"+json[i].area_name+"</option>";
}
$("#country").append(optionObg);
}
}
});
}
4.PHP
(1)获取省列表
public function register(){
//获取省级地区
$province=M('areas')->where(array('parent_id'=>1))->select();
$this->assign('province',$province);
$this->display();
}
(2)获取市/县
public function getArea(){
$where['parent_id']=I('areaId');
$area=D('areas')->where($where)->select();
$area['count']=count($area);
$this->ajaxReturn($area,'json');
}