美工兼顾SEO,为企业电子商务营销助力!
用php+javascript实现二级级联菜单的制作一佰互联网站建设(www.yinxi.net) 发布时间:2019-05-01 19:06:48 浏览数: 76 |
大体思路是这样的:为了不让先前的页面刷新,我用iframe潜入了一个二级子页面,用来读取数据库中的数据,最后把想要的数据传递给父级页面,完成数据的选择和转移。 主要程序代码如下(部分代码有改动,但不影响功能): 父页面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> |
TAG标签: 用php+javascript实现二级级联菜单的制作 |
上一篇:在同一窗体中使用PHP来处理多个提交任务 下一篇: 轻松修复Discuz!数据库 |
[返回新闻列表] |