首先,php端代码如下:
public function house_add(){ $PRovincelist = M('area')->where(array('area_parent_id'=>0,'area_deep'=>1))->select(); $this->assign('provincelist',$provincelist); $this->assign('country',C("country")); $this->assign('property_type',C("property_type")); $this->display(); }然后,html端代码如下:
<div class="form-group" id="pcd" > <label class="col-sm-3 control-label no-padding-right" for="form-field-4">省市区:</label> <div class="col-sm-9"> <select id="province" name="province"> <option value=''>请选择</option> <volist name="provincelist" id="po"> <option value='{$po.area_id}'>{$po.area_name}</option> </volist> </select> <select id="city" name="city"><option value=''>请选择</option></select> <select id="district" name="district"><option value=''>请选择</option></select> <span class="error_msg" id='error_district'></span> </div> </div>接着,jq代码如下:<script>//加载市区下拉 $('#province').change(function(){ var pid = $(this).val(); $.get("/Home/House/address",{'pid':pid}, function (i) { if(i.status=='1'){ $('#city').append(i.data); } },'json'); }) $('#city').change(function(){ var cid = $(this).val(); $.get("/Home/House/address",{'cid':cid}, function (i) { if(i.status=='2'){ $('#district').append(i.data); } },'json'); }) </script>最后上address的代码://省市区联动 public function address(){ //市 $pid = I('get.pid'); $citylist = M('area')->where(array('area_parent_id'=>$pid,'area_deep'=>2))->select(); if($citylist){ $cityinfo =''; foreach ($citylist as $key=>$val) { $cityinfo .='<option value="'.$val['area_id'].'">'.$val['area_name'].'</option>'; } echo json_encode(array('status'=>1,'data'=>$cityinfo)); } // 县 $cid = I('get.cid'); $areaslist = M('area')->where(array('area_parent_id'=>$cid,'area_deep'=>3))->select(); if($areaslist){ $areasinfo = ""; foreach ($areaslist as $k=>$v) { $areasinfo .='<option value="'.$v['area_id'].'">'.$v['area_name'].'</option>'; } echo json_encode(array('status'=>2,'data'=>$areasinfo)); } }
新闻热点
疑难解答