Home  >  Article  >  Web Front-end  >  Select dynamic rendering code in js to achieve secondary linkage

Select dynamic rendering code in js to achieve secondary linkage

不言
不言Original
2018-08-25 10:15:242158browse

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([&#39;element&#39;, &#39;form&#39;, &#39;layer&#39;], 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=&#39;&#39;>请选择</option>");
$.each(data, function(i,item){
var t = item.text, v = item.value, option = "<option value=&#39;"+v+"&#39;>"+t+"</option>";
arr.push(option);
})
$("#"+id).empty();
$("#"+id).append(arr.join(""));
form.render(&#39;select&#39;);
})
}
//表单提交
form.on(&#39;submit(save)&#39;,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(&#39;select(oaalFtype)&#39;, 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn