layui之动态添加下拉菜单

转:https://blog.csdn.net/Code_shadow/article/details/80431937

(不显示一定要先把select标签写上,不能标签也动态生成,那样会不显示 )

//html
<select id="selectID"></select>
//js
$.ajax({
    url:'departmentAction_findAllDepartment.action',
    dataType:'json',
    type:'post',
    success:function(data){

        $.each(data,function(index,item){
            $('#selectID').append(new Option(item.name,item.id));//往下拉菜单里添加元素
        })

        form.render();//菜单渲染 把内容加载进去
    }
})


posted @ 2022-03-23 08:46  离。  阅读(546)  评论(0编辑  收藏  举报