zoukankan      html  css  js  c++  java
  • Layui下拉3级联动

    这里我就不给大家详细说明了直接附图:

      

    js代码:

    layui.use(['layer', 'form','xform','layer'], function () {
    var element = layui.element;
    var form = layui.form;
    var layer = layui.layer;

    // 城市列表
    $.ajax({
    url:"/city/findById",
    type:"GET",
    async: false,
    cache: false,
    contentType: 'application/json',
    dataType: "json",
    success: function (json) {
    console.log(json);
    var CityListHTML='';
    for (var i=0; i<json.data.length; i++){
    CityListHTML+= '<option value="'+json.data[i].id+'">'+json.data[i].name+'</option>'
    }
    $('#CityList').append(CityListHTML);
    form.render();

    // 区域列表
    form.on('select(CityList)', function(data){
    var CityListid = data.value;
    console.log(CityListid);
    if (CityListid != "Nonull"){
    document.getElementById('regionList').innerHTML='';
    document.getElementById('PoliceList').innerHTML='';
    document.getElementById('Community').innerHTML='';
    $.ajax({
    url:"/region/findById/"+CityListid,
    type:"GET",
    async: false,
    cache: false,
    contentType: 'application/json',
    dataType: "json",
    success: function (json) {
    console.log(json);
    document.getElementById('regionList').innerHTML='';
    var regionListHTML='';
    for (var i=0; i<json.data.length; i++){
    regionListHTML+='<option value="'+json.data[i].id+'">'+json.data[i].name+'</option>'
    }
    $('#regionList').append(regionListHTML);
    form.render();

    // 派出所列表
    form.on('select(regionList)', function(data){
    var regionListid = data.value;
    document.getElementById('PoliceList').innerHTML='';
    document.getElementById('Community').innerHTML='';
    $.ajax({
    url:"/localPoliceStation/findById/"+regionListid,
    type:"GET",
    async: false,
    cache: true,
    contentType: 'application/json',
    dataType: "json",
    success:function (json) {
    console.log(json);
    document.getElementById('PoliceList').innerHTML='';
    var PoliceListHTML='';
    for (var i=0; i<json.data.length; i++){
    PoliceListHTML+='<option value="'+json.data[i].id+'">'+json.data[i].name+'</option>'
    }
    $('#PoliceList').append(PoliceListHTML);
    form.render();

    // 社区列表
    form.on('select(PoliceList)', function(data){
    var PoliceListid = data.value;
    $.ajax({
    url:"/community/findById/"+PoliceListid,
    type:"GET",
    async: false,
    cache: false,
    contentType: 'application/json',
    dataType: "json",
    success:function (json) {
    console.log(json);
    document.getElementById('Community').innerHTML='';
    var CommunityHTML='';
    for (var i=0; i<json.data.length; i++){
    CommunityHTML+='<option value="'+json.data[i].id+'">'+json.data[i].name+'</option>'
    }
    $('#Community').append(CommunityHTML);
    form.render();
    }
    })
    })
    }
    })
    })
    }
    })

    }
    else {
    document.getElementById('regionList').innerHTML='';
    document.getElementById('PoliceList').innerHTML='';
    document.getElementById('Community').innerHTML='';
    form.render();
    }
    })
    }
    });
    form.render();
    });
  • 相关阅读:
    135 01 Android 零基础入门 02 Java面向对象 07 Java多态 03 多态的实现(难点) 02 向上转型
    leetcode-----169. 多数元素
    leetcode-----167. 两数之和 II
    leetcode-----136. 只出现一次的数字
    leetcode-----125. 验证回文串
    leetcode-----122. 买卖股票的最佳时机 II
    java实体类和json串字段名称不一致或者与map中字段名称不一致使用注解转化
    如何优雅的将Object转换成List
    java中远程调用接口springboot
    返回前端页面的属性名称和实体类的名称不一致用@JsonProperty
  • 原文地址:https://www.cnblogs.com/salvater/p/12002262.html
Copyright © 2011-2022 走看看