全国省市区(html和php部分)

HTML

<div class="dingwei">
        <span>分享区域:span>
        <select id='sheng' name="province" onChange="change(this,1)">
            <option value="0">选择省option>
            {loop $list $l}
            <option value="{$l['region_id']}">{$l['region_name']}option>
            {/loop}
        select>
        <select id='shi' name="city" onChange="change(this,2)">
            <option value="0">选择市option>
        select>
        <select id='qu' name="area">
            <option value="0">选择区option>
        select>
    div>

JS

//改变地区时的方法
function change(obj,type){
    var url ="{php echo $this->createMobileUrl('Get_area')}";
    loading(1);
    $.post(url,{"id":obj.value,"type":type,act:'area'},function(res){
        loading(0);
        if(type == 1){
            if(obj.value>0){
                $("#shi").html(res);
                $("#qu").html("");
            }else{
                $("#shi").html("");
                $("#qu").html("");
            }
        }else if(type ==2){
            if(obj.value>0){
                $("#qu").html(res);
            }else{
                $("#qu").html("");
            }
        }
    })
}

PHP

//查询数据库地区
$list = pdo_fetchall("select region_name,region_id from ".tablename('shop_region')." where parent_id=:parent_id", array(':parent_id'=>1));
    //改变地区时的方法
    public function doMobileGet_area(){
        global $_GPC,$_W;
        if($_W['isajax']){
            if(intval($_GPC['type']) > 0){
                if(intval($_GPC['id'])>0){
                    $lists = pdo_fetchall("select * from ".tablename('shop_region')." where parent_id=:parent_id", array(':parent_id'=>intval($_GPC['id'])));
                    $type = $_GPC['type'];
                    if($type == 1){
                        $str="";
                    }else if($type == 2){
                        $str="";
                    }
                    foreach ($lists as $v) {
                        $str.="";
                    }
                    echo $str;
                    exit();
                }
            }
        }
    }

数据表SQL内容结构


实际应用项目截图
全国省市区(html和php部分)_第1张图片

数据库部分内容截图
全国省市区(html和php部分)_第2张图片

你可能感兴趣的:(学习资料)