三级联动菜单
html
<p>
<label>区域</label>
<select name="province" id="province" onchange="region('province','city','1')">
<option value="">省份</option>
{$region_province}
</select>
<select name="city" id="city" onchange="region('city','district','2')">
<option value="">地级市</option>
</select>
<select name="district" id="district">
<option value="">市、县级市</option>
</select>
</p>
js
<script type="text/javascript"> function region(t,p,type){ var a =document.getElementById(t).value; $.ajax({ url: "index.php?action=ajax_region&parent_id="+a+"&retion_type="+type, success: function(html){ html += "<option value=''>请选择</option>"; $("#"+p).html(html) } }); } </script>
ajax,php代码
function region($parent_id,$region_type){ //region(0,北京市)
$where = "where parent_id = $parent_id";
$sql = mysql_query("select * from rv_region $where");
//echo $where;
while($re = mysql_fetch_row($sql)){
$arr[] = $re;
}
if($region_type =='1'){
$province .= "<option value=''>地级市</option>";
}else if($region_type =='2'){
$province .= "<option value=''>市、县级市</option>";
}
foreach($arr as $k=>$val){
$province .= "<option value='".$val[0]."'>".$val[2]."</option>";
}
return $province;
}
$parent_id = $_GET['parent_id'];
$region_type = $_GET['retion_type'];
echo region($parent_id,$region_type);
三级联动mysql数据

浙公网安备 33010602011771号