简体   繁体   English

如何在引导模式中的表中附加行

[英]How to append row in a table in bootstrap modal

I have a bootstrap modal .我有一个引导模式。 Now I want to append a new row in my table that stand on modal body.现在我想在我的表中添加一个新行,该行位于模态主体上。

I can append any html content in my modal body but cant append in table.我可以在模态正文中附加任何 html 内容,但不能在表格中附加。 I am trying with this but not work.我正在尝试这个,但没有用。

   $('#mymodal').find('.modal-body tbody').append('<tr><td>new row<td></tr>');

This is example of bootstrap-modal and table with in. Append row working proper here.这是bootstrap-modaltable示例。在这里追加行正常工作。

 $('#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">&times;</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>john@example.com</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>mary@example.com</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>july@example.com</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>

May this code help you.愿此代码对您有所帮助。

try using after instead of append:尝试使用 after 而不是 append:

('#mymodal').find('.modal-body tbody:last-child').after('<tr><td>new row<td></tr>');

Alternatively you may also try using append a little differently:或者,您也可以尝试以不同的方式使用 append:

$('#mymodal').find('.modal-body tbody')
    .append('<tr>')
    .append('<td>new row<td>');

possibly related/dupe: Add table row in jQuery可能相关/欺骗: 在 jQuery 中添加表格行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM