您的位置:首页 > 编程语言 > PHP开发

thinkphp 三级联动

2014-05-20 18:47 197 查看
数据库在这里下载 数据库三级联动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);
}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: