加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 05:24:29 所属栏目:PHP教程 来源:网络整理
导读:大体思路是这样的:为了不让先前的页面刷新,我用iframe潜入了一个二级子页面,用来读取数据库中的数据,最后把想要的数据传递给父级页面,完成数据的选择和转移。 主要程序代码如下(部分代码有改动,但不影响功能): 父页面reg.html: iframesrc=”city.p

大体思路是这样的:为了不让先前的页面刷新,我用iframe潜入了一个二级子页面,用来读取数据库中的数据,最后把想要的数据传递给父级页面,完成数据的选择和转移。 主要程序代码如下(部分代码有改动,但不影响功能):
父页面reg.html: <iframesrc=”city.php”width=”300″height=”22″frameborder=”0″scrolling=”no”><inputname=”city”type=”hidden”id=”city”value=”"/> 子页面city.php: <scriptlanguage=”javascript”type=”text/javascript”>
functiongoto(n){
this.location.href=”city.php?sh_id=”+n;
}
<selectname=”sh”onchange=”goto(this.value)”>

<?php
include_once(”db.php”);
$sql=”selectfromprovinceorderbysh_idasc”;
$result=mysql_query($sql);
while($row=mysql_fetch_assoc($result)){
?>
<optionvalue=”<?echo$row[”sh_id”];?>”<?if($_GET[”sh_id”]==$row[”sh_id”]){echo'selected=”selected”‘;}?>><?echo$row[”sh_name”];?>
<?php
}
?>

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

<?php
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)){
?>
<optionvalue=”<?echo$row[”city_name”];?>”><?echo$row[”city_name”];?>
<?php
}
}
?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读