[英]How to limit the cloned table rows to 4?
=== table html structure === ===表格HTML结构===
<div id="table-container">
<table cellspacing="0" cellpadding="0">
<thead>
<tr>
<td>Table head text</td>
<td>Table head text</td>
<td>Table head text</td>
<td>Table head text</td>
<td>Table head text</td>
</tr>
</thead>
<tbody>
<tr class="row">
<td width="10%" data-group="group" data-id="table1-row1-col1" data-type="integer" class="cell-editable" title="Click to input data"></td>
</tr>
<tr class="row">
<td width="10%" data-group="group" data-id="table1-row2-col1" data-type="integer" class="cell-editable" title="Click to input data"></td>
</tr>
<tr class="row">
<td width="10%" data-group="group" data-id="table1-row3-col1" data-type="integer" class="cell-editable" title="Click to input data"></td>
</tr>
<tr class="row">
<td width="10%" data-group="group" data-id="table1-row4-col1" data-type="integer" class="cell-editable" title="Click to input data"></td>
</tr>
<tr class="row">
<td width="10%" data-group="group" data-id="table1-row4-col1" data-type="integer" class="cell-editable" title="Click to input data"></td>
</tr>
</table>
</div>
=== jquery === === jQuery ===
$( '#addNewTable' ).click(function() {
var source = $( '#table-container' ),
clone = source.clone( true );
clone.insertAfter( source )
.find( 'tbody tr td' ).not( 'tbody tr td:first-child, tbody tr td.title' ).text('')
.find( 'tr.expend_row input[type="hidden"]' ).siblings().remove();
});
Try this, 尝试这个,
clone.find("tr").eq(3).nextAll().remove();
or in your case change your code like this, 或者您这样更改代码,
$( '#addNewTable' ).click(function() {
var source = $( '#table-container' );
clone = source.clone( true );
clone.find("tr").eq(3).nextAll().remove();
clone.insertAfter( source )
.find( 'tbody tr td' ).not( 'tbody tr td:first-child, tbody tr td.title' ).text('')
.find( 'tr.expend_row input[type="hidden"]' ).siblings().remove();
});
$('td:eq(1)').clone();
$('td:eq(2)').clone();
$('td:eq(3)').clone();
$('td:eq(4)').clone();
you can clone td one by one first four rows by applying this step or you can also append it to other as; 您可以通过应用此步骤一一克隆前四行td,也可以将其附加到另一行;
$('td:eq(1)').appendTo('.your-class-name');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.