1. 程式人生 > >layui之動態新增下拉選單

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();//選單渲染 把內容載入進去
    }
})