LayUI中实现上级下拉框动态加载下级下拉框js

时间:2021-11-08 09:14:18

js代码:

var form = layui.form, layer = layui.layer;
form.on("select(上级)", function(data){
	var url = Const.apiUrl + "获取下级下拉框集合的Url";
	View.get(url, "khlx=" + data.value, function(resp) {
		$("select[name='下级']").html("");
		var html = "<option value>--属性名称--</option>";
		for (var i = 0; i < resp.length; i++) {
			html += "<option value = '" + resp[i].key +"'>" + resp[i].value +"</option>";
		}
		$("select[name='下级']").append(html);
		// 刷新select选择框渲染
		form.render();
	}, function() {
		TmplUtils.showMsgFail(Locale.get("custRiskRateConfig.info.propFail"));
	});
});

   参考:https://jingyan.baidu.com/article/afd8f4deafd30634e386e950.html