省市县三级联动

来源:互联网 发布:淘宝下图工具 免费 编辑:程序博客网 时间:2024/04/29 00:29
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>省市县三级联动</title></head><body><!--select 发生改变时调用函数 linkage()  接受改变之后的value --><select id="sheng" onchange="linkage(this.value,'shi')"></select>省<select id="shi" onchange="linkage(this.value,'xian')"></select>市<select id="xian"></select></body></html><script type="text/javascript">function linkage(id,p){var xmlhttp=new XMLHttpRequest();   //AJAX初始化var url = "./area.php?id="+id+"&r="+Math.random();  //传输id到php文件中 且防止缓存xmlhttp.open("get",url,true);  xmlhttp.send(null);    //发送数据xmlhttp.onreadystatechange = function (){   //获取当前状态if(xmlhttp.readyState == 4){document.getElementById(p).innerHTML = xmlhttp.responseText;}}}linkage("",'sheng')</script>




PHP 取出数据库内容,显示在select中

<?phpinclude("../include/dbconn.php"); //连接数据库@$id=$_GET["id"];  //防止直接进入php文件显示$sql="select id,name from area where id like '".$id."__'";$rs=mysql_query($sql);echo "<option value='0'>==请选择==</option>";while($rows=mysql_fetch_assoc($rs)){  echo '<option value=\''.$rows['id'].'\'>'.$rows['name'].'</option>';//在select中显示库中的数据name}?>


<?php//打开连接mysql_connect("localhost","root","");//选择数据库mysql_select_db("hbsi10php");//设置编码mysql_query("set names utf8");?>





下载:

http://www.3gput.com/forum.php?mod=viewthread&tid=141&extra=page%3D1