html代码$(function(){
var html1="<option value='请选择'>请选择</option>";
$("#select2").append(html1);
$("#select3").append(html1);
$('#select1').change(function(){
var pid=$('#select1').val();
$.getJSON("__URL__/sheng",{pid:pid}, function(json){
$("#select2").empty();
$("#select3").empty();
$("#select2").append(html1);
$("#select3").append(html1);
$.each(json, function(i,item) {
var html="";
html+="<option value="+item.cityID+">"+item.city+"</option>";
$("#select2").append(html);
});
});
});
$('#select2').change(function(){
var pid2=$('#select2').val();
$.getJSON("__URL__/shi",{pid2:pid2}, function(json){
$("#select3").empty();
$("#select3").append(html1);
$.each(json, function(i,item) {
var html="";
html+="<option value="+item.areaID+">"+item.area+"</option>";
$("#select3").append(html);
});
});
});
});
控制器代码<form name="myform" action="" method="post">
省份:
<select id="select1" name="select1">
<option value='请选择'>请选择</option>
<volist name="list" id="vo">
<option value="{$vo.provinceID}" id="{$vo.provinceID}">
{$vo.province}
</option>
</volist>
</select>
市:
<select id="select2" name="select2">
</select>
县:
<select id="select3" name="select3">
</select>
</form>
public function index(){
$administrator= D('province');
$list=$administrator->select();
$this->assign('list',$list);
$this->display();
}
public function sheng(){
$city= D('city');
$pid=$_REQUEST['pid'];
$where['father']=$pid;
$data=$city->where($where)->select();
echo json_encode($data);
}
public function shi(){
$city= D('area');
$pid=$_REQUEST['pid2'];
$where['father']=$pid;
$data=$city->where($where)->select();
echo json_encode($data);
}