用php实现真正的----连动下拉列表

5 篇文章 0 订阅
 

/***************************
* 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" οnchange="changes();">
<option value="0">请选择...</option>
<option value="北京">北京</option>
<option value="通化">通化</option>
</select>&nbsp;
<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(/"/", /"/");list.options[$i] = tmp;";
$str .= "</script>";

echo $str;
?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值