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;
?>
文章来源于领测软件测试网 https://www.ltesting.net/