我想在用戶點擊添加更多按鈕後動態添加行。我使用jquery來做這一切工作正常,但是當我嘗試加載從數據庫中獲取的選擇框的值和顯示內部循環。雖然我試圖通過jquery追加選擇框,但我得到了這個錯誤。善良的幫助。需要動態添加行
回顧這段代碼和錯誤信息
<table class="table table-bordered form-horizontal"id="size_variants_table">
<thead>
<tr>
<th>Size</th>
<th>Price</th>
<th>Quantity</th>
<th></th>
</tr>
</thead>
<tbody
<tr class="control-group">
<td class="control-label">
<select class="form-control" name="product_size[]" id="mylist">
<option value="<?php echo 12;?>"><?php echo 12;?></option></select>
</td>
<td>
<input type="text" name="product_size_price[]" class="form-control"/>
</td>
<td>
<input type="text" name="product_size_qty[]" id="product_size_qty" class="form-control product_size_qty" onchange="valuecheck();"/>
</td>
<td><span id='removeButton' /><i class="icon-trash bigger-130"></i></span></td>
</tr>
</tbody>
</table>
<input type='button' value='Add Button' id='addButton' />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#addButton").click(function() {
if(($('.form-horizontal .control-group').length+1) > 12222) {
alert("Only 2 control-group allowed");
return false;
}
var id = ($('.form-horizontal .control-group').length + 1).toString();
$('.form-horizontal').append('<tr class="control-group" id="control-group' + id + '"><td class="control-label" for="inputEmail' + id + '"><select class="form-control" name="product_size[]"> <option value="<?php echo 12;?>"><?php echo 12;?></option></select></td><td class="control-label" for="inputEmail' + id + '"><input type="text" id="inputEmail' + id + '" placeholder="Email"></td><td class="control-label" for="inputEmail' + id + '"><input type="text" id="inputEmail' + id + '" placeholder="Email"></td></tr>');
});
$("#removeButton").click(function() {
if ($('.form-horizontal .control-group').length == 1) {
alert("No more textbox to remove");
return false;
}
$(".form-horizontal .control-group:last").remove();
});
});
</script>
歡迎SO。我們不是在線調試器。請訪問[幫助]併發布信息。在這種情況下,查看視圖源代碼,您可能會發現由PHP – mplungjan
PS生成的換行符:如果您使用append(\'......)更改'append('.....')'...... \')'它可能在更新的瀏覽器中效果更好 – mplungjan