テーブルに別の行を動的に追加しようとしていますが、1行しか追加されず、もう追加されません。
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[]' class='input-small'></td>
<td><input type='text' name='bath[]' class='input-small'></td>
<td><input type='text' name='sqrt[]' class='input-small'></td>
<td><input type='text' name='price[]' 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 class='btn btn-danger btn-small'>remove</button></td>
</tr>
</tbody>
</table>
ここにjsがあります:
<script type="text/javascript">
$(document).ready(function() {
var tblrow = $('table.property_units tr.rows:first-child').clone();
$(".addrow").click(function() {
$("table.property_units").append(tblrow);
});
});
</script>
append でテーブルの行を書き出していないことに注意してください。書きたくないので、解決策として追加しないでください。コードが非常に厄介になります。