级联菜单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了级联菜单相关的知识,希望对你有一定的参考价值。

<?php 
    header("content:text/html;charset=utf8");
    [email protected]_connect("localhost","root","");
    mysql_select_db("hnthdl",$con);
    mysql_query("set name utf8");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<script>
    function selectcity(x){
        if(x!="请选择"){
            window.location.href=‘test.php?pid=‘+x;
        }
    }
    function selecttown(x){
        if(x!="请选择"){
            window.location.href=‘test.php?cid=‘+x+"&pid="+form1.hnthdl_area.value;
        }
    }
</script>
<body>
    <?php 
        session_start();
        if($_GET[pid]!=""){ $_SESSION["pid"]=$_GET[pid]; }
        if($_GET[cid]!=""){ $_SESSION["cid"]=$_GET[cid]; }
     ?>
<form  name="form1">
  <table width="300" border="0"   cellpadding="0"   cellspacing="0">   
      <tr   align="center">
        <td   height="30" colspan="2"   nowrap><span class="STYLE2">级联菜单的应用</span></td>
      </tr>
      <tr   align="center">
        <td width="120"   height="23"   nowrap><span class="STYLE1">省级名称:   </span></td>   
         <td width="180" align="left"   nowrap><select   name="hnthdl_area" onChange="selectcity(this.value);" > 
           <option  value="请选择"> 请选择</option>   
         <?php 
          $query=mysql_query("select * from hnthdl_area");
          $myrow=mysql_fetch_array($query);
          if($query==true){
            do{ 
        ?> 
           <option value="<?php echo $myrow["id"];?>"
          <?php
            if($_SESSION["pid"]!="") {
            if($_SESSION["pid"]==$myrow[id]){
                 echo "selected=\"selected\""; 
            }
        }?> ><?php echo $myrow[name];?></option>   
           <?php
          }while($myrow=mysql_fetch_array($query));
           }?>
         </select></td>
        </tr>
            <tr   align="center">
             <td   height="23"   nowrap class="STYLE1">市级名称:</td>
                <td align="left"   nowrap> 
          <?php if($_GET[pid]!="") { ?>
        <select   name="hnthdl_area1" onChange="selecttown(this.value);">
            <option  value="请选择" selected="selected"> 请选择</option>             
          <?php $query=mysql_query("select * from hnthdl_area1 where pid=‘".$_GET[pid]."‘");
                    if($query==true){
          while($myrow1=mysql_fetch_array($query)){                ?>
            <option   value="<?php echo $myrow1[id];?>" 
          <?php
         if($_SESSION["cid"]!=""){
              if($_SESSION["cid"]==$myrow1[id]){
               echo "selected=\"selected\"";    
          }
           }?>><?php echo $myrow1[name1];?></option>
           <?php }}?>
          </select>
          <?php }  ?>  </td>
        </tr>
             <tr   align="center">
               <td   height="23"   nowrap class="STYLE1">县/镇级名称:</td>
               <td align="left"   nowrap>
        <?php if($_GET[cid]!=""){ ?>
        <select   name="hnthdl_area1">     
        <?php 
        $query=mysql_query("select * from hnthdl_area2 where cid=‘".$_GET[cid]."‘");
        if($query==true){
                     while($myrow1=mysql_fetch_array($query)){           ?>
           <option   value="<?php echo $myrow1[id];?>"><?php echo $myrow1[name2];?></option>
           <?php }}?>
        </select>
        <?php  } ?> </td>
            </tr>   
         </table>   
    </form> 
</body>
</html>

 

以上是关于级联菜单的主要内容,如果未能解决你的问题,请参考以下文章

js实现级联菜单(没有后台)

Python/Tkinter:级联菜单锚定在右侧而不是左侧

ASP.NET MVC 级联下拉菜单

SQL级联查询 商品类型级联菜单查询

yii实现级联下拉菜单的方法

[伪] 级联菜单,两级菜单