<>LayUI Of select Dynamic linkage
To achieve linkage effect, pay attention to two points :
first : You need to be able to listen select Of change event ;
second : Content loaded asynchronously , You need to render it again Normal use .
html code :
<form class="layui-form batchinput-form" action="" id="box-form"> <div class="
layui-form-item" > <div class="layui-input-inline"> <label class="
layui-form-label"> Province :</label> <div class="layui-input-block" > <select name="
province" id="province" lay-filter="myselect"> <option value=""> Please select a province </option> <
#list province as provincelist> <option value="${provincelist.areaId}">
${provincelist.fullname}</option> </#list> </select> </div> </div> </div> <div
class="layui-form-item"> <div class="layui-input-inline"> <label class="
layui-form-label"> City :</label> <div class="layui-input-block"> <select name="
City" id="City" lay-filter="myselect2" > </select> </div> </div> </div> <div
class="layui-form-item"> <div class="layui-input-inline"> <label class="
layui-form-label"> Region :</label> <div class="layui-input-block"> <select name="
Area" id="Area" lay-filter="myselect3"> </select> </div> </div> </div> </form>
js:
layui.use(['layer', 'form',"jquery"], function(){ var layer = layui.layer ,$=
layui.jquery ,form = layui.form; form.on('select(myselect)', function(data){ var
areaId=(data.value).replaceAll(",",""); $.ajax({ type: 'POST', url: ' Access to data url',
data: {" Dynamic parameter name ":areaId}, dataType: 'json', success: function(data){ $("#City").
html(""); $.each(data, function(key, val) { var option1 = $("<option>").val(val.
areaId).text(val.fullname); // adopt LayUI.jQuery Add list item $("#City").append(option1);
form.render('select'); }); $("#City").get(0).selectedIndex=0; } }); }); });
1.select Of chage Monitoring event usage
form.on(‘select(myselect)’, function(data){}) among myselect yes select Of
lay-filter Property value
2. Data is loaded asynchronously into select Of option After middle school , Click the select You'll find out layui The selection effect of does not work , Need to use
form.render(‘select’); Render again , It can be used normally .
Technology