用php实现真正的----连动下拉列表
2004-09-23 10:16
531 查看
/***************************
* author : 大龄青年
* email : wenadmin@sina.com
* from: http://blog.csdn.net/hahawen
***************************/
下面的两个文件copy到同一个文件下,通过web路径访问index.html看看吧,这个是通过iframe来实现的连动更新,list.php目前的内容比较简单,你看通过list.php来进行数据库查询,然后显示出查询的结果列表。
index.html
<body>
<form name="myfrm">
<select name="mlist" onchange="changes();">
<option value="0">请选择...</option>
<option value="北京">北京</option>
<option value="通化">通化</option>
</select>
<select name="slist">
</select>
<iframe id="frame" src="list.php?city=" style="display:none;"></iframe>
<script language="javascript">
function changes(){
frame.location.href = "list.php?city=" + document.myfrm.mlist.value;
}
</script>
</form>
</body>
list.php
<?php
$data = array("北京"=>array("小强","旺财","小强他爹"),
"通化"=>array("小温","小宋","他们儿子"),);
$city = $_GET["city"];
$result = $data[$city];
$str = "<script language=/"javascript/">list = parent.document.myfrm.slist;list.length = 0;";
if($result==null)
$str .= "tmp = new Option(/"....../", /"/");list.options[0] = tmp;";
else
foreach($result as $i => $value)
$str .= "tmp = new Option(/"{$value}/", /"{$value}/");list.options[$i] = tmp;";
$str .= "</script>";
echo $str;
?>
* author : 大龄青年
* email : wenadmin@sina.com
* from: http://blog.csdn.net/hahawen
***************************/
下面的两个文件copy到同一个文件下,通过web路径访问index.html看看吧,这个是通过iframe来实现的连动更新,list.php目前的内容比较简单,你看通过list.php来进行数据库查询,然后显示出查询的结果列表。
index.html
<body>
<form name="myfrm">
<select name="mlist" onchange="changes();">
<option value="0">请选择...</option>
<option value="北京">北京</option>
<option value="通化">通化</option>
</select>
<select name="slist">
</select>
<iframe id="frame" src="list.php?city=" style="display:none;"></iframe>
<script language="javascript">
function changes(){
frame.location.href = "list.php?city=" + document.myfrm.mlist.value;
}
</script>
</form>
</body>
list.php
<?php
$data = array("北京"=>array("小强","旺财","小强他爹"),
"通化"=>array("小温","小宋","他们儿子"),);
$city = $_GET["city"];
$result = $data[$city];
$str = "<script language=/"javascript/">list = parent.document.myfrm.slist;list.length = 0;";
if($result==null)
$str .= "tmp = new Option(/"....../", /"/");list.options[0] = tmp;";
else
foreach($result as $i => $value)
$str .= "tmp = new Option(/"{$value}/", /"{$value}/");list.options[$i] = tmp;";
$str .= "</script>";
echo $str;
?>
相关文章推荐
- 用php实现真正的----连动下拉列表(转载)
- html+js+PHP(使用了smarty模板技术)+mysql实现二级动态下拉列表(select)
- php递归实现无限分类生成下拉列表的函数
- html+js+PHP(使用了smarty模板技术)+mysql实现二级动态下拉列表(select)
- php jquery ajax json 全国省市区三级联动下拉列表 简单实现
- JAVA EE 项目经常使用知识 之AJAX技术实现select下拉列表联动的两种使用方法(让你真正理解ajax)
- php递归实现无限分类生成下拉列表的函数
- jQuery结合PHP+MySQL实现二级联动下拉列表[实例]
- jQuery结合PHP+MySQL实现二级联动下拉列表[实例]
- html+js+PHP(使用了smarty模板技术)+mysql实现二级动态下拉列表(select)
- jQuery结合PHP+MySQL实现二级联动下拉列表[实例]
- PHP 无限极分类下拉列表实现
- php jquery ajax json 全国省市区三级联动下拉列表 简单实现
- JAVA EE 项目常用知识 之AJAX技术实现select下拉列表联动的两种用法(让你真正理解ajax)
- mysql+php select 下拉列表树的简单实现
- JAVA EE 项目常用知识 之AJAX技术实现select下拉列表联动的两种用法(让你真正理解ajax)
- JAVA EE 项目常用知识 之AJAX技术实现select下拉列表联动的两种用法(让你真正理解ajax)
- php jquery ajax json 全国省市区三级联动下拉列表 简单实现
- php递归实现无限分类生成下拉列表
- jQuery结合PHP+MySQL实现二级联动下拉列表[实例]