zoukankan      html  css  js  c++  java
  • 三级联动菜单

    html

    <p>
                      <label>区域</label>
                    <select name="province" id="province" onchange="region('province','city','1')">
                        <option value="">省份</option>
                        {$region_province}
                    </select>
                    <select name="city" id="city" onchange="region('city','district','2')">
                         <option value="">地级市</option>
                        
                    </select>
                    <select name="district" id="district">
                         <option value="">市、县级市</option>
                      
                    </select>
                    
                  </p>

    js

    <script type="text/javascript">
                  function region(t,p,type){ 
                    var a =document.getElementById(t).value;                  
                      $.ajax({
                            url: "index.php?action=ajax_region&parent_id="+a+"&retion_type="+type,
                            success: function(html){
                                html += "<option value=''>请选择</option>";
                                $("#"+p).html(html)
                            }
                      });
                  }
                  </script>

    ajax,php代码

    function region($parent_id,$region_type){           //region(0,北京市)
        $where = "where parent_id = $parent_id";
        
        $sql = mysql_query("select * from rv_region $where");
        //echo $where;
        while($re = mysql_fetch_row($sql)){
            $arr[] = $re;    
        }
        if($region_type =='1'){
            $province .= "<option value=''>地级市</option>";
        }else if($region_type =='2'){
            $province .= "<option value=''>市、县级市</option>";    
        }
        
        foreach($arr as $k=>$val){
            $province .= "<option value='".$val[0]."'>".$val[2]."</option>";
            
        }
        
        return $province;
    }   
    
    $parent_id = $_GET['parent_id'];
    $region_type = $_GET['retion_type'];
        
    echo region($parent_id,$region_type);

    三级联动mysql数据

  • 相关阅读:
    CJB的大作
    OI省选算法汇总
    bzoj1078【SCOI2008】斜堆
    zrt中文题
    bzoj4726【POI2017】Sabota?
    bzoj4591 【Shoi2015】超能粒子炮·改
    bzoj2086【Poi2010】Blocks
    bzoj2091【Poi2010】The Minima Game
    bzoj2038小z的袜子
    bzoj4282慎二的随机数列
  • 原文地址:https://www.cnblogs.com/wesky/p/3438139.html
Copyright © 2011-2022 走看看