table
<table id = "tablePoSub" name = "tablePoSub" class="layui-table" style="width: 500px;">
<thead>
<tr>
<th></th>
<th>库位名称</th>
<th>库位描述</th>
</tr>
</thead>
<tbody>
<#if sotreHouce.store_house_info.store_room_list ??>
<#list sotreHouce.store_house_info.store_room_list as storeRoom>
<tr id="${storeRoom.store_room_id}">
<input type="hidden" name="store_room_id" value="${storeRoom.store_room_id}">
<td>
<input class ="laytable-cell-checkbox" lay-skin="primary" type="checkbox" name="storeCheck" value="${storeRoom.store_room_id}">
</td>
<td>
<input class="layui-input" name="store_room_name" value="${storeRoom.store_room_name}" type="text">
</td>
<td>
<textarea class="layui-input" name="store_room_desc" style="height: 50px" type="text">${storeRoom.store_room_desc}</textarea>
</td>
</tr>
</#list>
</#if>
</tbody>
</table>
点击按钮添加一行
document.getElementById('addRow').addEventListener('click',function (data) {
var tr=' <tr id="">\n' +
' <td>\n' +
' <input class ="laytable-cell-checkbox" lay-skin="primary" type="checkbox" name="storeCheck" value="">\n' +
' </td>\n' +
' <td>\n' +
' <input type="hidden" name="store_room_id" value="">\n' +
' <input class="layui-input" name="store_room_name" value="" type="text">\n' +
' </td>\n' +
' <td>\n' +
' <textarea class="layui-input" name="store_room_desc" style="height: 50px" type="text"></textarea>\n' +
' </td>\n' +
' </tr>';
$("#tablePoSub tbody:last").append(tr);
layui.use('form', function(){
var form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
form.render();
});
});
点击删除一行
$("input[name='storeCheck']:checked").each(function() { // 遍历选中的checkbox
n = $(this).parents("tr").index(); // 获取checkbox所在行的顺序
$("table#tablePoSub").find("tr:eq("+(n+1)+")").remove();
});