我需要通过jquery中的clone方法逐个删除表中动态创建的行,并且我需要删除第一行。并且还需要执行空检查,但有...... [英] i need to delete the dynamically created rows in a table by clone method in jquery ,one by one, and i d'nt need to delete the first row. and also need to perform the null check ,but there are...
问题描述
< script type =text / javascript>
$(document).ready(function(){< br $>
$(#but)。click(function(){
var newRow = $( '#tb tbody> tr:last')。clone(true).appendTo('table')
.find('input')。val('');
返回false;
});
$(#delete)。click(function(){
if($('tb tbody> tr:last')。最近(tr)== $('#tb tbody> tr:first')){
break ;
}
else {
$('#tb tbody> tr:last')。remove();
返回false;
}
});
});
< / script>
我的html文件包含
<script type="text/javascript" >
$(document).ready(function(){
$("#but").click(function (){
var newRow = $('#tb tbody>tr:last').clone(true).appendTo('table')
.find('input').val('');
return false;
});
$("#delete").click(function(){
if($('#tb tbody>tr:last').closest("tr")==$('#tb tbody>tr:first')){
break;
}
else{
$('#tb tbody>tr:last').remove();
return false;
}
});
});
</script>
And my html file contain
<form name="form1" action="interview.php" method="POST"><button id="but">add</button><button id="delete">delete</button>
<table id="tb" >
<tbody>
<tr><td>name:</td><td><input type="text" name="name[]"></td><td>ACC NO</td><td><input type="text" name="acc_no[]"></td></tr>
</tbody>
</table>
<input type="submit" value="submit">
</form>
推荐答案
(document).ready(function(){
(document).ready(function(){
(#but)。click(function(){
var newRow =
("#but").click(function (){
var newRow =
('#tb tbody> tr:last')。clone(true).appendTo('table')
.find('input')。val('');
返回false;
});
('#tb tbody>tr:last').clone(true).appendTo('table')
.find('input').val('');
return false;
});
这篇关于我需要通过jquery中的clone方法逐个删除表中动态创建的行,并且我需要删除第一行。并且还需要执行空检查,但有......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!