Blogger Information
Blog 40
fans 0
comment 0
visits 29401
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
三级联动--2019-05-23
小人物的博客
Original
558 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>作业:  三级联动菜单</title>
</head>
<body>
        <label for="pm">品名</label>
        <select name="" id="pm"></select>

        <label for="pp">***</label>
        <select name="" id="pp"></select>

        <label for="xh">型号</label>
        <select name="" id="xh"></select>

        <p id="addr"></p>

        <script src="../0522/static/js/jquery-3.4.1.js"></script>
        <script>
 
            $.getJSON('inc/a.json',function(data) {
                var option = '<option value="">选择系统</option>';
                //取回数据,叠加到option中
                $.each(data,function (index) {
                    option += '<option value="' +data[index]['pmId']+'">'+data[index]['pmName']+'</option>';
                });
                //符值给pm下拉
                $('#pm').html(option);
               });

            $('#pm').change(function() {
                $.getJSON('inc/b.json',function(data) {
                     var option = '<option value="">选择***</option>';
                     //取回数据,叠加到option中
                     $.each(data,function (index) {
                        if (data[index]['pmId'] === parseInt($('#pm').val())) {
                        option += '<option value="' +data[index]['ppId']+'">'+data[index]['ppName']+'</option>';
                        }
                     });
                     console.log(option);
                     $('#pp').html(option);
                });
            });
            $('#pp').change(function() {
                $.getJSON('inc/c.json',function(data) {
                    var option = '<option value="">选择***</option>';
                    //取回数据,叠加到option中
                    $.each(data,function (index) {
                        if (data[index]['ppId'] === parseInt($('#pp').val())) {
                            option += '<option value="' +data[index]['xhId']+'">'+data[index]['xhName']+'</option>';
                        }
                    });
                    $('#xh').html(option);
                });
            });
        </script>
</body>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post