一、select必须在form表单内,form表单的class必须是class=“layui-form”
<form class="layui-form" action="">
<label class="layui-form-label">角色:</label>
<div class="layui-input-block" style="width:13rem;">
<select id="role" lay-search="roleSelect">
<option value="" ></option>
</select>
</div>
</form>
二、select标签必须要有lay-search lay-filter="xxx"的属性(这里要注意select的这个属性和form.on(submit)在标签里设置的不一样,submit的是lay-sumbit)
例如:
/*
*select
*/
<select id="role" lay-search lay-filter="roleSelect">
<option value="" ></option>
</select>
/*
*submit
*/
<button id="addPeopleBtn" type="button" class="layui-btn"
lay-sumbit lay-filter="addPeople">新增人员</button>
三、form.on 要在在layui.use({})里面写
layui.use(['table','form','layer'], function(){
form.on('select(xxx)',function () {
$.ajax({
url: '/HelthyCheckupPc/deptController/deptList',
dataType:"json",
success: function (data) {
for (let i=0;i<data.length;i++){
$("#dept").append("<option value=\""+data[i].deptId+"\" >"+data[i].deptName+"</option>")
}
}
})
})
})