手机
当前位置:查字典教程网 >编程开发 >php教程 >用php+javascript实现二级级联菜单的制作
用php+javascript实现二级级联菜单的制作
摘要:大体思路是这样的:为了不让先前的页面刷新,我用iframe潜入了一个二级子页面,用来读取数据库中的数据,最后把想要的数据传递给父级页面,完成...

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

主要程序代码如下(部分代码有改动,但不影响功能):

父页面reg.html:

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

子页面city.php:

<scriptlanguage=”javascript”type=”text/javascript”>

functiongoto(n){

this.location.href=”city.php?sh_id=”+n;

}

</script>

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

<option>请选择所在省市</option>

<?php

include_once(”db.php”);

$sql=”select*fromprovinceorderbysh_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”];?></option>

<?php

}

?>

</select>

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

<option>选择你所在的城市</option>

<?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”];?></option>

<?php

}

}

?>

</select>

【用php+javascript实现二级级联菜单的制作】相关文章:

php实现图片转换成ASCII码的方法

用PHP实现标准的IP Whois查询

Php+SqlServer实现分页显示

用PHP产生动态的影像图

PHP编实现程动态图像的创建

使用php的swoole实现高效安全的ftp服务器

使用函数递归实现基于php和MySQL的动态树型菜单

最好用的JavaScript开发工具和代码编辑器

用PHP实现小型站点广告管理

php实现求相对时间函数

精品推荐
分类导航