layui 下拉菜单选中触发事件示例
要点:给select一个layui-filter属性,用Layui自带的表单监听事件功能
<div class="layui-form" > <div class="layui-form-item"> <div class="layui-inline"> <label class="layui-form-label">选择框</label> <div class="layui-input-inline"> <select lay-filter="district" name="modules" lay-verify="required" lay-search> <option value="">直接选择</option> <option value="1">layer</option> <option value="2">form</option> <option value="3">layim</option> <option value="4">element</option> </select> </div> </div> </div> </div>
layui.use(['form'], function(){ var form = layui.form; form.on('select(district)', function(data){ alert(data.value); // 获取选中的值 form.render('select'); }) });