當我嘗試刪除第一行它的工作原理,但我添加更多的行我不能刪除它們。出於某種原因,我只能刪除第一行。動態刪除行不會工作,只刪除第一行而不刪除其他人
這裏是我的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>
可能重複的[jQuery的如何onclick事件綁定到動態添加HTML元素(http://stackoverflow.com/questions/1525664/jquery-how-to-bind-on-click-event-to-dynamic-added-html-element) – Barmar
我已經看到你列出的示例,但它不是很清楚。我的例子對讀者非常清楚,代碼非常清晰,乾淨。 –
如果這個問題不清楚,也許與其相關的許多問題之一。這個問題每天都會被問到,其中一個問題應該有你理解的答案。 – Barmar