当我尝试删除第一行时,它可以工作,但是当我添加更多行时,我无法删除它们。出于某种原因,我只能删除第一行。
这是我的html
<table class="pretty property_units" style="width:800px;">
<thead>
<tr>
<th>Bedroom</th>
<th>Bathroom</th>
<th>Square Feet</th>
<th>Price</th>
<th>Available</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr class="rows">
<td><input type='text' name='bedroom[]' value='0' class='input-small'></td>
<td><input type='text' name='bath[]' value='0' class='input-small'></td>
<td><input type='text' name='sqrt[]' value='0' class='input-small'></td>
<td><input type='text' name='price[]' value='0' class='input-small'></td>
<td>
<select name='avail[]' class='input-small'>
<option value='yes'>Yes</option>
<option value='no'>No</option>
</select>
</td>
<td><button type="button" class="btn btn-danger btn-small removeRow">remove</button></td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-small btn-primary addrow">add row</button>
这是我的js
<script type="text/javascript">
$(document).ready(function() {
$(".addrow").click(function() {
var tblrow = $('table.property_units tr.rows:last').clone();
$("table.property_units tbody").append(tblrow);
});
$(".removeRow").click(function() {
$(this).closest("tr").remove();
return false;
});
});
</script>