简体   繁体   English

使用数据表打开模式

[英]opening a modal using datatable

I'm so confused what the problem in my code is. 我很困惑我的代码中的问题是什么。 I've already tried this working code but it doesn't work for me. 我已经尝试过此工作代码,但对我不起作用。

I've also already tried 'toggle' and that doesn't work either. 我也已经尝试过'toggle' ,但也不起作用。

This is my code: 这是我的代码:

 $(document).ready(function() { $('#example').on('click', 'tr', function() { $("#inbox_modal").modal('show'); }); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/css/bootstrap.min.css" /> <table id="example" class="table table-bordered inbox" style="width:100%"> <div class="modal fade" id="inbox_modal" role="dialog"> <div class="modal-dialog modal-lg"> <!-- Modal content--> <div class="modal-content modal-form"> <div class="modal-header"> <h4 class="modal-title">Example</h4> <a data-dismiss="modal" style="cursor: pointer">&times;</a> </div> <div class="modal-body"> <p>POP UP ME!!!</p> </div> </div> </div> </div> 

The code works fine. 该代码工作正常。 Just fix markup of the table and make sure the Bootstrap components are included to your page. 只需修复表的标记,并确保Bootstrap组件包含在页面中即可。

 $(document).ready(function() { $('#example').on('click', 'tr', function() { $("#inbox_modal").modal('show'); }); }); 
 <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.min.css"/> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.18/css/dataTables.bootstrap4.min.css"/> <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/js/bootstrap.min.js"></script> <script type="text/javascript" src="https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js"></script> <script type="text/javascript" src="https://cdn.datatables.net/1.10.18/js/dataTables.bootstrap4.min.js"></script> <table id="example" class="table table-bordered inbox"> <tbody> <tr> <td>Click</td> <td>here</td> <td>please</td> </tr> </tbody> </table> <div class="modal fade" id="inbox_modal" role="dialog"> <div class="modal-dialog modal-lg"> <!-- Modal content--> <div class="modal-content modal-form"> <div class="modal-header"> <h4 class="modal-title">Example</h4> <a data-dismiss="modal" style="cursor: pointer">&times;</a> </div> <div class="modal-body"> <p>POP UP ME!!!</p> </div> </div> </div> </div> 

It seems to work on my end. 这似乎对我有效。 You have to display tr a row where the user could click and show the modal. 您必须在用户可以单击并显示模式的行上显示tr

Here added on your code <td><tr><tr></td> 在此处添加您的代码<td><tr><tr></td>

 $(document).ready(function() { $('#example').on('click', 'tr', function() { $("#inbox_modal").modal('show'); }); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/css/bootstrap.min.css" /> <table id="example" class="table table-bordered inbox" style="width:100%"> <tr><td><td></tr> <div class="modal fade" id="inbox_modal" role="dialog"> <div class="modal-dialog modal-lg"> <!-- Modal content--> <div class="modal-content modal-form"> <div class="modal-header"> <h4 class="modal-title">Example</h4> <a data-dismiss="modal" style="cursor: pointer">&times;</a> </div> <div class="modal-body"> <p>POP UP ME!!!</p> </div> </div> </div> </div> </table> 

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

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