我在表格中有一个表单。在那张表中我有输入字段的行。我有两个选项用于删除行和添加行。在添加行时,用户将点击一个新行将被添加,当用户点击删除行时,最后一行将被删除。所有这些工作正常。但我有一个问题,假设我点击了删除行选项,最后一行将被删除,这样所有的行都被删除。现在再次点击添加行时,它不会添加新行。那么有人能解决这个问题吗?下面是该在jQuery中删除所有行时不添加新行
<!DOCTYPE HTML>
<html lang="en-IN">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<script type="text/javascript" src="jquery1.7.2.js"></script>
<body>
<style type="text/css">
table td {
border: 1px solid #666;
}
</style>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#add-line").click(function() {
var row = jQuery('.form-fields tbody>tr:last').clone(true);
row.find("input:text").val("");
row.insertAfter('.form-fields tbody>tr:last');
return false;
});
jQuery('#remove-row').live('click',function(event){
jQuery(this).parent().parent().remove();
});
});
</script>
<div id="form">
<table id="form-headings">
<tr>
<td width="15%">Remove Rows</td>
<td width="15%">Product</td>
<td width="16%">Description</td>
<td width="13%">Unit Cost</td>
<td width="14%">Quantity</td>
<td width="12%">Discount</td>
<td width="14%">Total</td>
</tr>
</table>
<div class="row">
<div class="form-fields">
<table>
<tr>
<td><input type="button" id="remove-row" value="Remove Row" /></td>
<td><input type="text" id="form_product" size="5px"/></td>
<td><input type="text" id="form_description" size="5px"/></td>
<td><input type="text" id="form_unit_cost" size="5px"/></td>
<td><input type="text" id="form_quantity" size="5px"/></td>
<td><input type="text" id="form_discount" size="5px"/></td>
<td><input type="text" id="form_total" size="5px"/></td>
</tr>
</table>
</div>
</div>
<input type="button" id="add-line" value="Add Line" />
</div>
</body>
</html>
那么该怎么做?解决这个问题的最佳解决方案是什么? –
查看我更新的代码.. –
@sushanta reddy好的..好吧,它在这里工作。你能告诉我这里有什么样的原型吗? –