| 用php实现真正的连动下拉列表 |
|
| |
|
|
下面的两个文件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; ?>
 |
频道声明:本频道的文章除部分特别声明禁止转载的专稿外,可以自由转载.但请务必注明出出处和原始作者 文章版权归本频道与文章作者所有.对于被频道转载文章的个人和网站,我们表示深深的谢意。
| 原始作者:佚名 |
录入时间:2006-11-9 |
| 信息来源:不详 |
投稿信箱:itqoo@126.com |
|
|
 |
|
|
|
| 教程录入:admin 责任编辑:admin |
|
上一个教程: PHP 实现的字典序排列算法
下一个教程: php如何更好更有效的实现-----用户注册页面 |
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |