如何使用JavaScript在菜单内创建子菜单

时间:2018-12-06 02:43:11

标签: javascript

我可以知道如何使用javascript在菜单内创建子菜单。我尝试创建菜单,但不确定是否创建子菜单

创建菜单和子菜单的代码

 $.ajax({
    type: "GET",
    url: '',
    success: function (data, status, xhr) {
        data = JSON.parse(data);


            $.each(data.Table[i], function (key, values) {
                var li = document.createElement('li');
                li.innerHTML = "<a href='#homeSubmenu' data-toggle='collapse' aria-expanded='false' class='dropdown-toggle'><i class='fas fa-layer-group'></i>" + key + "</a> <li class='collapse list-unstyled' id='homeSubmenu'> </li >";
                document.getElementById('dropdown').appendChild(li);
                var li1 = document.createElement('li');
                li1.innerHTML = "<li class='collapse list-unstyled' id='homeSubmenu'> </li >";
                document.getElementById('homeSubmenu').appendChild(li1);


                $.each(values, function (i, val) {
                    $("<li>", { text: val }).appendTo(li1);
                });
            });




        }
    },
    error: function (xhr) {
        alert(xhr.responseText);
    }
});

菜单的HTML

        <ul class="list-unstyled components" id="dropdown">


        </ul>

0 个答案:

没有答案