layui实现最新2024省市区三级联动下拉选择代码

代码语言:html

所属分类:其他

代码描述:layui实现最新2024省市区三级联动下拉选择代码

代码标签: layui 最新 2024 省市区 三级 联动 下拉 选择 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>省市区三级联动</title>
    <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/layui.2.9.10.css">
    <style>
        .container {
          
            margin: 0 auto;
            padding: 20px;
        }
        #loading, #error {
            text-align: center;
            font-style: italic;
            color: #666;
        }
        #error {
            color: #f00;
        }
    </style>
</head>

<body>
    <div class="layui-container container">
        <h1 class="layui-title">layui省市区三级联动选择</h1>
        <div id="loading" class="layui-text">正在加载数据...</div>
        <div id="error" class="layui-text" style="display: none;"></div>
        <form class="layui-form" action="">
            <div class="layui-form-item">
                 
                <div class="layui-input-inline">
                    <select id="province" name="province" lay-filter="province">
                    <option value="">请选择省</option>
                </select>
                </div>
                <div class="layui-input-inline">
                    <select id="city" name="city" lay-filter="city">
                    <option value="">请选择市</option>
                </select>
                </div>
                <div class="layui-input-inline">
                    <select id="district" name="district" lay-filter="district">
                    <option value="">请选择区</option>
                </select>
                </div>
            </div>
        </form>
    </div>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/layui.2.9.10.js"></script>
    <script>
        layui.use(['form', 'jquery'], function(){
            var form = layui.form;
            var $ = layui.jquery;
    
            var provinceSelect = $('#province');
            var citySelect = $('#city');
            var districtSelect = $('#district');
            var loadingDiv = $('#loading');
            var errorDiv = $('#error');
    
            let data = [];
    
            async function fetchCSVData(url) {
                try {
                    const response = await fetch(url);
                    if (!response.ok) {
                        throw new Error(`HTTP error! status: ${response.status}`);
                    }
                    const csvText = await response.text();
                    return csvText.split('\n').slice(1).filter(row => row.trim() !== '').map(row => {
                        const columns = row.split(',');
                        if (columns.length < 8) {
                            console.warn('Row with insufficient columns:', row);.........完整代码请登录后点击上方下载按钮下载查看

网友评论0