0
我有一個引導模式。現在我想在我的表格中添加一個新的行,它位於模態主體上。如何在引導模式中在表中追加行
我可以附加任何HTML內容在我的模態身體,但不能附加在表中。 我正在嘗試這個,但沒有工作。
$('#mymodal').find('.modal-body tbody').append('<tr><td>new row<td></tr>');
我有一個引導模式。現在我想在我的表格中添加一個新的行,它位於模態主體上。如何在引導模式中在表中追加行
我可以附加任何HTML內容在我的模態身體,但不能附加在表中。 我正在嘗試這個,但沒有工作。
$('#mymodal').find('.modal-body tbody').append('<tr><td>new row<td></tr>');
嘗試使用後,而不是追加:
('#mymodal').find('.modal-body tbody:last-child').after('<tr><td>new row<td></tr>');
另外,您也可以嘗試用少量追加不同:
$('#mymodal').find('.modal-body tbody')
.append('<tr>')
.append('<td>new row<td>');
可能與/欺騙:Add table row in jQuery
這是bootstrap-modal
和table
的示例,其中in。Ap Pend行在這裏工作。
$('#myModal').find('.modal-body .table tbody').append('<tr><td>newrow</td><td>newrow</td><td>newrow</td></tr>');
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container">
<h2>Modal Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
月這段代碼可以幫助您。
你能提供你的html嗎? – ankit