The content of this article is about the code for selecting dynamic rendering in js to achieve secondary linkage. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
The following is part of the html code
<div class="layui-form-item layui-row layui-col-space5"> <div class="layui-col-md6"> <label class="layui-form-label">一级分类</label> <div class="layui-input-block layui-select-block"> <select name="oaalFtype" id="oaalFtype" lay-filter="oaalFtype"></select> </div> </div> <div class="layui-col-md6"> <label class="layui-form-label">二级分类</label> <div class="layui-input-block layui-select-block"> <select name="oaalStype" id="oaalStype" lay-filter="oaalStype"></select> </div> </div> </div>
The following is part of the js
layui.use(['element', 'form', 'layer'], function(){ var $ = layui.jquery ,element = layui.element ,form = layui.form ,layer = layui.layer; //初始化下拉框 function initSelect(id,url){ $.post(url,function(result){ var data = result.data; var arr = new Array(); arr.push("<option value=''>请选择</option>"); $.each(data, function(i,item){ var t = item.text, v = item.value, option = "<option value='"+v+"'>"+t+"</option>"; arr.push(option); }) $("#"+id).empty(); $("#"+id).append(arr.join("")); form.render('select'); }) } //表单提交 form.on('submit(save)',function(data){ var options = { url: "${mbase}/saveOaAssetlib.do", type: "POST", success: function (data) { if(data.success){ layer.alert(data.messages[0],{icon: 1},function(){ window.close(); window.opener.location.reload(); }); } } }; $("#formData").ajaxSubmit(options); }) //一级分类 var oaalFtype = "${base}/risen/pub/dictCombo.action?uuid=/DICT/OA/ASSETLIB/FTYPE&TYPE=jsn_grid"; initSelect("oaalFtype",oaalFtype); //批次 var oaalBatch = "${base}/risen/pub/dictCombo.action?uuid=/DICT/OA/ASSETLIB/BATCH&TYPE=jsn_grid"; initSelect("oaalBatch",oaalBatch); //监控一级分类 form.on('select(oaalFtype)', function(data){//2级联动 //二级分类初始化 var oaalStype = "${base}/risen/pub/dictCombo.action?uuid=/DICT/OA/ASSETLIB/FTYPE/"+encodeURI(data.value)+"&TYPE=jsn_grid"; initSelect("oaalStype",oaalStype); }); });
Related recommendations:
js implements Select secondary linkage example in HTML Share
AngularJS implementation of select secondary linkage drop-down menu step-by-step explanation
The above is the detailed content of Select dynamic rendering code in js to achieve secondary linkage. For more information, please follow other related articles on the PHP Chinese website!