thinkphp 三级联动

数据库在这里下载    数据库三级联动
jquery代码

$(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);

});
});
});

});


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);
}


   
   


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值