三级联动 地图使用数据

html

<div class="container">
    <table class="table">
        <select class="sel" name="id_en"><option value="" class="first">一级分类</option></select>
        <select class="sel" name="id_on"><option value="" class="first">二级分类</option></select>
        <select class="sel" name="id_in"><option value="" class="first">三级分类</option></select>
    </table>
</div>

 js

$(function () {
    ajaxSel();
    $('.sel').change(function () {
        var pid=$(this).val();
        var _this=$(this);
        ajaxSel(pid,_this);
    })
    function ajaxSel(pid=0,_this='') {
        $.ajax({
            url:"sel",
            data:{pid:pid},
            type:'get',
            dataType:'json',
            success:function (res) {
                console.log(res);
                var e=res.data;
                var content='';
                $(e).each(function (i) {
                    content+="<option value='"+e[i].id+"'>"+e[i].name+"</option>";
                })
                //判断要追加的位置
                if(pid){
                    _this.next('select').find('option:not(.first)').remove();
                    _this.next().append(content);
                }else{
                    $('select:first').append(content)
                }
            }
        })
    }
})

 后台代码

public function sel(Request $request){
    //获取上级分类id
    $id=$request['pid'];
    //查询分类信息
    $date= city::sel($id)->Toarray();
    //返回json格式数据
    return json_encode(['code'=>200,'msg'=>'请求成功','data'=>$date]);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值