添加&单击按钮时减去TR(ID+1)
Add & Subtract TR on Button Click (ID +1)
嘿,我想为订单提供一张产品表。
我希望用户能够添加&减去行(添加和删除带有数量和备注的产品)
我把这些拼凑在一起,并在少数例外的情况下工作。
- 我需要每个输入的ID为+1,而val('')在新的输入/行上
- 减法按钮起作用,但删除最后一个&只有一行。移除自身&添加按钮
有人能给我举一些例子吗;第二行有减法按钮吗?或者引导我走向正确的方向?提前感谢-
HTML:
<table id="mytable" width="250px" border="0" cellspacing="0" cellpadding="0" style="text-align:center;>
<thead>
<tr class="product">
<th style="text-align:center;"><strong>Item</strong></th>
<th style="text-align:center;"><strong>Qty.</strong></th>
<th style="text-align:center;"><strong>Remarks</strong></th>
</tr>
</thead>
<tr name="product" class="product">
<td width="100px" style="padding-left:7px; padding-right:7px;"><input type="text" width="100px" name="product" id="product" /></td>
<td width="5px" style="text-align:center; padding-left:7px; padding-right:7px;"><input type="text"maxlength="2" name="qty" id="qty"></td>
<td width="100px" style="padding-left:7px; padding-right:7px;"><input type="text" name="remarks" id="remarks" /></td>
<td><input type="submit" name="add" id="add" value="+" style="width:20px; text-align:center;"/></td>
<td><input type="submit" class="subtract" value="-" style="width:20px; text-align:center; display:none;"/></td>
</tr>
</table>
我现在使用的:
$("#add").click(function() {
$('#mytable tbody>tr:last').clone(true).insertAfter('#mytable tbody>tr:last');
$('#mytable tbody>tr:last #product').val('');
$('#mytable tbody>tr:last #qty').val('');
$('#mytable tbody>tr:last #remarks').val('');
$('#mytable tbody>tr:last #add').val('+');
$("input.subtract").click(function() {
$(this).closest("tr").remove();
});
不要进行克隆,而是创建一个id等于$('#mytable tbody>tr: last')
id值+1的新tr
,并将其附加到表中。要删除具有特定id的tr
,请将其用作函数参数。在此功能中,删除此特定的tr
。(<input type="button" class="subtract" value="-" style="width:20px; text-align:center; display:none;" onClick="remove({id});"/>
)
相关文章:
- 如何在点击tr的td后获取tr的id's元素
- 正在获取循环中td元素的tr id
- 获得<tr>通常生成的ID
- 隐藏<tr>包含id中的变量's
- 选择具有动态 ID 的特定 tr 的特定 td
- j查询点击事件,用于在具有特定 ID 的表中动态添加 tr
- 如何在TR的最后一个TD中添加事件或将ID属性添加到IMG标签
- 正在JQUERY数据表的TR ID中设置数据行主ID
- 在javascript中使用tr id更新tr innerHTML
- 使用最接近的.attr获取错误的tr id
- 从同一个表中按tr id读取td值
- 创建<tr>在没有ID的表中使用JavaScript
- 基于TR ID从TD小区中删除类
- 添加&单击按钮时减去TR(ID+1)
- 无法通过TR id | datatable更新行
- 删除具有相同tr id的表之间的行
- 在jQuery中设置一个tr id
- 使用jQuery validate可以显示和隐藏TR ID元素吗
- 我需要将url与sharepoint列表tr id连接起来
- 使用jstl填充tr id标记