欢迎来到福编程网,本站提供各种互联网专业知识!

用php+javascript实现二级级联菜单的制作

发布时间:2008-05-06 作者: 来源:转载
二级级联菜单在我去年的时候就用asp+js做过,而现在忽然拿出来再做的时候我发现我忘记了,而且原来用asp写的程序都找不到了,真晕[emot]sweat[/emot],于是到网上搜,找了半天,我发现网上的写法各异,而且都特别复杂,这么一个二级级联菜单,有必要弄这么复

大体思路是这样的:为了不让先前的页面刷新,我用iframe潜入了一个二级子页面,用来读取数据库中的数据,最后把想要的数据传递给父级页面,完成数据的选择和转移。

主要程序代码如下(部分代码有改动,但不影响功能):
父页面reg.html:

子页面city.php:


functiongoto(n){
this.location.href=”city.php?sh_id=”+n;
}

<selectname=”sh”onchange=”goto(this.value)”>

include_once(”db.php”);
$sql=”select*fromprovinceorderbysh_idasc”;
$result=mysql_query($sql);
while($row=mysql_fetch_assoc($result)){
?>
>
}
?>

<selectname=”city”onchange=”parent.document.getElementById('city').value=this.value”>

if(!empty($_GET[”sh_id”])){
//echo“ok”;
$sql=”select*fromcitywheresh_id=”.$_GET[”sh_id”].”orderbycity_idasc”;
$result=mysql_query($sql);
while($row=mysql_fetch_assoc($result)){
?>
”>
}
}
?>

相关推荐