样板图:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d7976156583dc42aa38afeece0d8465f.png#pic_center)
html部分
<div class="layui-form-item" >
<label class="layui-form-label">路线</label>
<div class="layui-input-block" id="last">
<div class="layui-input-inline">
{empty name="$ways"}
<div class="layui-form-item">
<div class="layui-input-inline">
<input type="text" name="ways[]" placeholder="请输入"
autocomplete="off" class="form-control" style="width: 200%;">
</div>
<div class="layui-input-block" style="margin-left: 480px">
<button id="add" type="button" class="layui-btn layui-btn-warm layui-btn-sm">
<i class="layui-icon"></i>
</button>
</div>
</div>
{else /}
{volist name="ways" id="vo"}
<div class="layui-form-item">
<div class="layui-input-inline">
<input type="text" name="ways[]" lay-verify="required" value="{$vo.name}"
class="form-control" style="width: 200%;">
</div>
<div class="layui-input-block" style="margin-left: 480px">
<button type="button"
class="layui-btn layui-btn-danger layui-btn-sm removeclass"><i
class="layui-icon"></i></button>
</div>
</div>
{/volist}
<div class="layui-form-item">
<div class="layui-input-inline">
<input type="text" name="ways[]" placeholder="请输入"
autocomplete="off" class="form-control" style="width: 200%;">
</div>
<div class="layui-input-block" style="margin-left: 480px">
<button id="add" type="button" class="layui-btn layui-btn-warm layui-btn-sm">
<i class="layui-icon"></i>
</button>
</div>
</div>
{/empty}
</div>
</div>
</div>
js部分
layui.use(['element', 'jquery', 'layer', 'form', 'laydate'], function () {
var form = layui.form
, element = layui.element
, laydate = layui.laydate
, $ = layui.$;
$("#add").click(function () {
var str = '<div class="layui-form-item">' +
'<div class="layui-input-inline">' +
'<input type="text" name="ways[]" lay-verify="required"' +
'class="form-control" style="width: 200%;">' +
'</div>' +
'<div class="layui-input-block" style="margin-left: 480px">' +
'<button type="button" class="layui-btn layui-btn-danger layui-btn-sm removeclass"><i class="layui-icon"></i></button>' +
'</div>' +
'</div>';
$("#last").append(str);
x++;
});
$("body").on('click', ".removeclass", function () {
var approvalName = $(this).parent().prev('div.layui-input-inline').children().val();
var parentEle = $(this).parent().parent();
parentEle.remove();
});
})