如何使用javascript或jquery创建tr的克隆并在新行中插入数据
How to create clone of tr and insert data in new row using javascript or jquery?
<tr id="rptShippinRates_ctl01_A" class="row">
<td>
<div>
<input type="hidden" id="hdnSupplierShippingID" value="28">
</div>
<div class="gvColSet tLightBlack gvColAlignLeft" style="font-size: 12px;" title="Test1">Test1</div>
</td>
<td>
<div class="gvColSet tLightBlack gvColAlignLeft" style="font-size: 12px;" title="$ 10.00">$ 10.00</div>
</td>
<td>
<span id="SpnDeleteShipping" class="DelRow" title="Delete shipping rate" style="float: Left;margin-left: 8px;"></span>
</td>
</tr>
我想使用 JavaScript 或 jQuery 克隆它。任何帮助将不胜感激。
类似的东西:
.HTML:
<table>
<tr id="rptShippinRates_ctl01_A" class="row">
<td>
<div>
<input type="hidden" id="hdnSupplierShippingID" value="28">
</div>
<div class="gvColSet tLightBlack gvColAlignLeft" style="font-size: 12px;" title="Test1">Test1</div>
</td>
<td>
<div class="gvColSet tLightBlack gvColAlignLeft" style="font-size: 12px;" title="$ 10.00">$ 10.00
</div>
</td>
<td>
<span id="SpnDeleteShipping" class="DelRow" title="Delete shipping rate" style="float: Left;margin-left: 8px;"></span>
</td>
</tr>
</table>
.JS:
$('tr').clone().appendTo('table');
JSfiddle: http://jsfiddle.net/P8Tkf/此外,您还必须删除 ID,因为 ID 必须是唯一的。
var $tr = $('tr.row'); // fidn the row you want to work with
$tr // grab the row
.clone() // clone it
.prop('id','...') // change its id
.find('td:eq(0)') // find the first <td>
.find('input') // find hidden input
.val('...') // change its value
.end()
.find('.gvColSet') // find the nested gvColSet
.text('...') // change its text
.prop('title','...') // and change its title
.end()
.end()
.find('td:eq(1)') // find second <td>
.find('.gvColSet') // find the nested gvColSet
.text('...') // change its text
.prop('title','...') // and its title
.end()
.end()
.appendTo($tr.closest('table')); // append it to the same table
相关文章:
- 使用jquery将mysql数据获取到新的表行中
- 阻止ReSharper将JavaScript函数参数放到新行中
- HTML表内容:如果行很长,如何在新行中显示部分内容
- 在新行中显示现有项目中的表行中的值
- 用于在表中添加行的Javascript代码将单元格中的数据复制到新行中
- 将字符串结果返回到表单元格中的新行中
- 如何在剑道网格中添加具有预定义数据的新行
- 数据表中的fnAddData()添加到同一行,而不是添加到新行
- 在数据表的新行中添加按钮,变得未定义
- 当数据达到 10 行时,如何将数据放在新列中
- 如何在不影响 Jquery 数据表中其他行的情况下删除选定的现有数据并添加新行
- 如何使用javascript或jquery创建tr的克隆并在新行中插入数据
- 使用数据表(Meteor Tabular)在新行中绘制数组的每个元素
- 如何在7个字母/字母表/数字和新行中的新字母后的键向上插入分隔符-Jquery
- 文本区域值在新行中
- 如何从表中的每个新行中删除类
- 字符串在源代码的新行中中断,而不是在浏览器中
- 用下拉菜单在新行中选择文本
- 在新行中输出模板字符串
- 从数据库中保留新行的数据