layui動態新增的資料事件失效問題----解決辦法
阿新 • • 發佈:2018-11-16
關於該問題的layui官方文件地址:http://www.layui.com/doc/modules/form.html
<div class="layui-form-item"> <label class="layui-form-label">類別</label> <div class="layui-input-inline"> <select id="GoodsAddModel_GoodsCategorySel" lay-verify="required" lay-search=""> @*動態新增類別*@ </select> </div> </div>
$.ajax({ url: "/Goods/GetGoodsCategory", data: {}, type: "post", async: false, success: function (data) { if (data != "" && data != null) { layui.use(['layer', 'form'], function () { var form = layui.form; var length = data.length; var html1 = '<dd lay-value="" class="layui-select-tips layui-this">直接選擇或搜尋選擇</dd>'; var html2 = '<option value="" >直接選擇或搜尋選擇</option>'; for (var i = 0; i < length; i++) { html1 += '<dd lay-value="' + data[i].CategoryId + '">' + data[i].CategoryName + '</dd>'; html2 += '<option value="' + data[i].CategoryId + '">' + data[i].CategoryName + '</option>'; } $("#GoodsAddModel_GoodsCategorySel").next().children().eq(1).html(html1); $("#GoodsAddModel_GoodsCategorySel").html(html2); form.render();//沒有寫這個,操作後沒有效果 }); } } });