用 js 实现 省市县三级联动 调取数据库省市县数据
效果图
html页面:
所在地区:
对应 html 中的 js
对应 控制器
// 初加载页面的时候,要把 所有省的值 遍历显示到页面
// 显示 省份
$pro_model=M('dqprovinces');
$province = $pro_model->select();
$this->assign("province",$province);
js 中对应的控制器,返回对应 下属市县列表
// 页面 ajax 返回 省 下面的市
public function ajax_chooseMarket(){
$id = I('post.id');
$city_model=M('dqcities');
$where['provinceid'] = $id;
$result = $city_model->where($where)->select();
// var_dump($result);
// die;
$this->ajaxReturn($result,'JSON');
}
// 遍历 市 下面的 县
public function ajax_chooseArea(){
// 接收传过来的id
$id = I('post.id');
$area_model=M('dqareas');
$where['cityid'] = $id;
$result = $area_model->where($where)->select();
// var_dump($result);
// die;
$this->ajaxReturn($result,'JSON');
}