//点击事件的按钮
<button type="button" class="layui-btn" id="addpeop">
<i class="layui-icon"></i>
</button>
$("#addpeop").click(function(){
var peop=$("#areas");
var t=$(['<div class="layui-form-item" id="areas">',
'<label class="layui-form-label">绑定医院</label>',
'<div class="layui-form layui-input-inline" lay-filter="provinces">',
'<select name="province" id="provinces'+i+'" lay-search="" class="state">',
'</select>',
'</div>',
'<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" id="del">删除</button>',
'</div>'].join(''));
t.find('#del').on('click', function(){
t.remove();
});
prosle(i);
i=i+1;
peop.after(t);
layui.form.render("select");
})
})
//结束添加
//回显动态框
{//赋值可选的也就是动态生成的select
var peop=$("#areas");/* ;*/
prosle(indexs);
var t=$(['<div class="layui-form-item" id="areas">',
'<label class="layui-form-label">绑定医院</label>',
'<div class="layui-form layui-input-inline" lay-filter="provinces" >',
'<select name="province" id="provinces'+indexs+'" lay-search="" class="state">',
'<option selected value='+ item.hosid+ '> '+ item.hosname + ' </option>',//绑定医院
'</select>',
'</div>',
'<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" id="del">删除</button>',
'</div>'].join(''));
t.find('#del').on('click', function(){
t.remove();
});
peop.after(t);
layui.form.render("select");
}
indexs=indexs+1;//循环一次加一
layui动态添加select选择框和回显
最新推荐文章于 2024-09-06 16:13:14 发布