基于PCASClass.js和layui.js的城市三级联动

Posted superfeeling

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于PCASClass.js和layui.js的城市三级联动相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="../Public/js/layui/css/layui.css" />
        <title></title>
    </head>

    <body>
        <div class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">城市</label>
                <div class="layui-input-inline">
                    <select id="province" name="org_province" lay-filter="org_province">
                    </select>
                </div>
                <div class="layui-input-inline">
                    <select id="city" name="org_city" lay-filter="org_city">
                    </select>
                </div>
                <div class="layui-input-inline">
                    <select id="area" name="org_area" lay-filter="org_area">
                    </select>
                </div>
            </div>
        </div>
        <script type="text/javascript" src="../Public/js/layui/layui.js"></script>
        <script type="text/javascript" src="../Public/js/PCASClass.js"></script>
    </body>
    <script>
        var mypcas = new PCAS("org_province", "org_city", "org_area", "请选择省份", "请选择城市", "请选择地区");
        layui.use([form], function() {
            var form = layui.form;
            var province;
            form.on(select(org_province), function(data) {
                province = data.value;
                //不清除的话,layui高版本会出现选项重复
                document.getElementById("province").innerHTML="";
                document.getElementById("city").innerHTML="";
                document.getElementById("area").innerHTML="";
                var mypcas = new PCAS("org_province", "org_city", "org_area", province, "请选择城市", "请选择地区");
                form.render(select);
            });
            form.on(select(org_city), function(data) {
                //不清除的话,layui高版本会出现选项重复
                document.getElementById("province").innerHTML="";
                document.getElementById("city").innerHTML="";
                document.getElementById("area").innerHTML="";
                var mypcas = new PCAS("org_province", "org_city", "org_area", province, data.value, "请选择地区");
                form.render(select);
            });
        });
    </script>

</html>

 

以上是关于基于PCASClass.js和layui.js的城市三级联动的主要内容,如果未能解决你的问题,请参考以下文章

layui的引用js踩坑

js插件

前端框架layui

layui.js一直加载不了的问题

layui时间组件的应用

layui数据表格的使用(前端和后端)