使用ajax实现三级联动菜单
index.html文件 <head> var xhr;
<body onload="getArea('','t_province')"> <?php mysql_connect('localhost','root',''); mysql_select_db('china'); mysql_query('set names utf8'); //获得用户点击的值以及应该显示的表明 $val=$_POST['val']; $table=$_POST['table']; if($table=='t_province'){ //查询所有的省 $sql="select ProName from $table order by ProSort"; $result=mysql_query($sql); $rows=array(); while($row=mysql_fetch_row($result)) { echo "<option>$row[0]</option>"; } }else if($table=='t_city'){ $sql="select CityName from t_city where ProId=(select ProID from t_province where ProName = '$val')"; $result=mysql_query($sql); $rows=array(); while($row=mysql_fetch_row($result)) { echo "<option>$row[0]</option>"; } }else if($table=='t_district'){ $sql="select DisName from t_district where CityID=(select CityID from t_city where CityName='$val')"; $result=mysql_query($sql); $rows=array(); while($row=mysql_fetch_row($result)) { echo "<option>$row[0]</option>"; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |