下面的兩個文件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;
?>