我发现了一些代码,我修改了相同但现在我想克隆我在克隆元素中从原始div输入中输入的内容
<button type="button" id="addmore" >Add More</button>
<button type="button" id="rmvbtn" >Remove</button>
<div class="dynamic-wrapper">
<div class="datagrid">
<table>
<thead>
<tr>
<th>Item</th>
<th>UM</th>
</tr>
</thead>
<tbody>
<tr>
<td><p><strong>1</strong></p>
</td>
<td>
<div class="dynamic-row">
<input type="text" name="chpob1" id="chpob1" />
</div>
</td>
</tr>
</tbody>
</table></div></div>
Jquery就在这里!
http://jsfiddle.net/MetCastle/6uhQt/
希望你能帮助我,谢谢
答案 0 :(得分:0)
那样的东西?
$(document).ready(function() {
var increment = 2;//First clone line number
$('#addmore').on('click', function(){
var original = $('.dynamic-row:eq( 0 )').closest('tr');
var cloneDiv = original.clone();
//Increment line number
$('strong', cloneDiv).html(increment++);
original.closest('table').append(cloneDiv);
});
$('#rmvbtn').on('click', function(){
if(increment > 2){
$('.dynamic-row:last').closest('tr').remove();
//decrease line number
increment--;
}
});
});