当上一行/当前行被填充时,将新行添加到HTML表中
Add a new row to an HTML table when the previous/current is filled
我时间紧迫,会尽量简短,如果我的解释有问题,我会在晚上编辑。
简单地说,我有一个表,名称和年龄,当页面加载一行时,它就会开始。当第一行填充了非空的内容时,另一行自动加载为空。
我更喜欢使用JavaScript,但我也可以使用asp.net进行管理。我希望我能很好地解释自己,很抱歉这么简短。
如有任何帮助,我们将不胜感激。
编辑:编码
<table class="table table-striped" style="margin:10px" id="tablaSKU" runat="server">
<thead>
<tr>
<th></th>
<th>SKU</th>
<th>Precio €</th>
<th>Descripción</th>
<th>Fecha Inicio Demo</th>
<th>Fecha Fin Demo</th>
<th>Tipo de préstamo</th>
</tr>
</thead>
<tbody>
<tr>
<th>1-</th>
<th class="col-sm-2" name="sku"><asp:TextBox ID="sku" runat="server" class="form-control"></asp:TextBox></th>
<th class="col-sm-1"><asp:TextBox ID="precio" runat="server" class="form-control"></asp:TextBox></th>
<th class="col-sm-3"><asp:TextBox ID="descripProd" runat="server" class="form-control"></asp:TextBox></th>
<th class="col-sm-2"><asp:TextBox ID="dataInit" runat="server" class="form-control"></asp:TextBox></th>
<th class="col-sm-2"><asp:TextBox ID="dataFin" runat="server" class="form-control"></asp:TextBox></th>
<th class="col-sm-2">
<asp:DropDownList ID="opcion" runat="server" CssClass="formularioChekLst form-control">
<asp:ListItem>Opciones : </asp:ListItem>
<asp:ListItem>Opción 1</asp:ListItem>
<asp:ListItem>Opción 2</asp:ListItem>
<asp:ListItem>Opcion 3</asp:ListItem>
</asp:DropDownList>
</th>
</tr>
</tbody>
</table>
HTML代码
<table class="table table-striped" style="margin:10px" id="tablaSKU" runat="server">
<thead>
<tr>
<th></th>
<th>SKU</th>
<th>Precio €</th>
<th>Descripción</th>
<th>Fecha Inicio Demo</th>
<th>Fecha Fin Demo</th>
<th>Tipo de préstamo</th>
</tr>
</thead>
<tbody>
<tr>
<th>1-</th>
<th class="col-sm-2"><input ID="sku" runat="server" class="form-control"></input></th>
<th class="col-sm-1"><input ID="precio" runat="server" class="form-control"></input></th>
<th class="col-sm-3"><input ID="descripProd" runat="server" class="form-control"></input></th>
<th class="col-sm-2"><input ID="dataInit" runat="server" class="form-control"></input></th>
<th class="col-sm-2"><input ID="dataFin" runat="server" class="form-control"></input></th>
<th class="col-sm-2">
<asp:DropDownList ID="opcion" runat="server" CssClass="formularioChekLst form-control">
<asp:ListItem>Opciones : </asp:ListItem>
<asp:ListItem>Opción 1</asp:ListItem>
<asp:ListItem>Opción 2</asp:ListItem>
<asp:ListItem>Opcion 3</asp:ListItem>
</asp:DropDownList>
</th>
</tr>
</tbody>
</table>
由于没有示例,我已经尽力解释了我认为你的意思,请参阅下面的示例。。。
HMTL:
<form id=myform>
<table id="mytable" data-row-prototype="<tr> <td>Name:</td> <td><input type="text" name="name[]"></td> </tr> <tr> <td>Age:</td> <td><input type="number" name="age[]"></td> </tr>">
</table>
</form>
jQuery:
var table = $('#mytable');
function appendRow() {
table.append(table.data('row-prototype'));
}
$(function() {
appendRow(); // Append the first row on page load
$('form#myform').on('change', function () {
var inputs = $(this).find(':input'),
valid = true;
$.each(inputs, function () {
if ($(this).val() == '') {
valid = false;
}
});
if (valid) {
appendRow();
}
});
});
相关文章:
- 保存表中的行's在数组中的tbody,稍后使用它们
- 禁用表中的行单击
- 获取表中每行的一列的内容,然后循环访问每个内容
- 当源工作表添加了行时,如何编写在一个工作表中添加行的脚本
- 如何在表中滑动行
- 什么'这是用javascript隐藏和显示表中所有行的最快方法
- 无法使用jQuery从表中删除行
- 使用'从HTML表中提取行的内容<tr onclick=alertContents()>'
- 如何比较单元格值和隐藏 html 表中的行
- 使用 for 循环基于
id 从表中删除行 - 无法从表中删除行
- 选择 html 表中的行
- 用于在表中添加行的Javascript代码将单元格中的数据复制到新行中
- 避免在引导程序3表中换行
- 按类名从表中删除行
- 两个表添加新行按钮-冲突
- 使用jQuery在HTML表中交替行
- 在数据表的新行中添加按钮,变得未定义
- 如何在不影响 Jquery 数据表中其他行的情况下删除选定的现有数据并添加新行
- 在表中插入行号,同时附加新行