• 三级联动菜单


    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数据

  • 相关阅读:
    【php】错误日志处理
    【php】正则表达式
    【php】字符串
    【PHP】数组
    【PHP】函数
    【PHP】流程控制
    【PHP】PHP运算符
    【PHP】PHP基本语法
    【前端】CSS总结
    SVN与Apache整合
  • 原文地址:https://www.cnblogs.com/wesky/p/3438139.html
Copyright © 2020-2023  润新知