亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

用php+javascript實(shí)現(xiàn)二級級聯(lián)菜單的制作

 更新時(shí)間:2008年05月06日 23:25:12   作者:  
二級級聯(lián)菜單在我去年的時(shí)候就用asp+js做過,而現(xiàn)在忽然拿出來再做的時(shí)候我發(fā)現(xiàn)我忘記了,而且原來用asp寫的程序都找不到了,真暈[emot]sweat[/emot],于是到網(wǎng)上搜,找了半天,我發(fā)現(xiàn)網(wǎng)上的寫法各異,而且都特別復(fù)雜,這么一個(gè)二級級聯(lián)菜單,有必要弄這么復(fù)雜嗎?于是自己想重新寫一個(gè)簡單的。在經(jīng)過半個(gè)小時(shí)左右的思考后,我完成了二級級聯(lián)菜單的設(shè)計(jì)和制作。
 

大體思路是這樣的:為了不讓先前的頁面刷新,我用iframe潛入了一個(gè)二級子頁面,用來讀取數(shù)據(jù)庫中的數(shù)據(jù),最后把想要的數(shù)據(jù)傳遞給父級頁面,完成數(shù)據(jù)的選擇和轉(zhuǎn)移。

主要程序代碼如下(部分代碼有改動,但不影響功能):
父頁面reg.html:

<iframe src=”city.php” width=”300″ height=”22″ frameborder=”0″ scrolling=”no”></iframe> <input name=”city” type=”hidden” id=”city” value=”" />

子頁面city.php:

<script language=”javascript” type=”text/javascript”>
function goto(n){
this.location.href=”city.php?sh_id=”+n;
}
</script>

<select name=”sh” onchange=”goto(this.value)”>
<option>請選擇所在省市</option>
<?php
include_once(”db.php”);
$sql=”select * from province order by sh_id asc”;
$result=mysql_query($sql);
while($row=mysql_fetch_assoc($result)){
?>
<option value=”<? echo $row[”sh_id”];?>” <? if($_GET[”sh_id”]==$row[”sh_id”]){echo 'selected=”selected”‘;}?>><? echo $row[”sh_name”];?></option>
<?php
}
?>
</select>
<select name=”city” onchange=”parent.document.getElementById('city').value=this.value”>
<option>選擇你所在的城市</option>
<?php
if(!empty($_GET[”sh_id”])){
//echo “ok”;
$sql=”select * from city where sh_id=”.$_GET[”sh_id”].” order by city_id asc”;
$result=mysql_query($sql);
while($row=mysql_fetch_assoc($result)){
?>
<option value=”<? echo $row[”city_name”];?>”><? echo $row[”city_name”];?></option>
<?php
}
}
?>
</select>

相關(guān)文章

最新評論