layui中监听select下拉框改变事件

前言:使用在如省市区三级联动,二级联动场景等场景
一、HTML部分通过lay-filer属性

<div class="layui-form-item">
	<label class="layui-form-label">所属组织</label>
	<div class="layui-input-inline">
		<script type="text/html" template>
			<select name="org_id" lay-filter="orgs" id="accountAdd" lay-verify="required">
          		<option value="">请选择</option>
       		</select>
       </script>
	</div>
</div>

二、JS部分

layui.use(['layer', 'jquery', 'form'], function () {
	var layer = layui.layer,
	$ = layui.jquery,
	form = layui.form;
	//这儿监听上面列表点击操作
	form.on('select(orgs)', function(data) {
		var org_id = data.value;
		var datas =`json={"Request":{"org_id":${org_id}},"Signed":${signed},"Action":"GetProject"}`;
		// 创建对象字段
		var dataLists = {}
		$.ajax({
			url: `${httpUrl}`,
			type: "POST",
			contentType: 'application/x-www-form-urlencoded',
			dataType: 'json',
			data: datas,
			success: function(res) {
				console.log(res)
				dataLists = res.List1
				for (var i = 0; i < dataLists.length; i++) {$('#project_id').append("<option   value=" + dataLists[i]['project_id'] + ">" + dataLists[i]['project_name'] +"</option>")
				}
				form.render('select');
			}
		});
	});
});
©️2020 CSDN 皮肤主题: 黑客帝国 设计师:上身试试 返回首页