【问题标题】:Bootstrap modal not trigerring after using the pagination from the datatable使用数据表中的分页后引导模式未触发
【发布时间】:2019-09-26 05:20:42
【问题描述】:

我正在使用 Bootstrap 和 Datatable。当我单击详细信息按钮时,会打开模式。在第一页分页中,当我单击详细信息按钮时,模式窗口正在正确打开,但是当我在第二页时,模式窗口没有触发。有人可以帮助我吗? 这是我的代码

我的数据表 javascript 是

 $(document).ready(function(){  
  $('.view_data').click(function(){  
       var employee_id = $(this).attr("id");  
       var data = table.row( this ).data();
       $.ajax({  
            url:"search_details.php",  
            method:"post",  
            data:{employee_id:employee_id},  
            success:function(data){  
                 $('#search_detail').html(data);  
                 $('#dataModal').modal("show");  
            }  
       });  
  });  
}); 

search_details.php 是获取记录详情的php页面

<?php  
if(isset($_POST["employee_id"]))  
{  
    include('../db.php');
  $output = '';  

  $query = "SELECT * FROM patent_search WHERE id = '".$_POST["employee_id"]."'";  
  $result = mysqli_query($con, $query);  
  $output .= '  
  <div class="table-responsive">  
       <table id="prodlist" class="table table-bordered">';  
  while($row = mysqli_fetch_array($result))  
  {  

这是触发模态的数据表中的详细信息按钮

 <input type="button" name="view" value="Details" id="<? echo $row["id"]; ?> class="btn btn-info btn-xs view_data" />

【问题讨论】:

  • 谁能帮帮我?
  • 在下面查看我的答案。

标签: jquery ajax datatables


【解决方案1】:

更新:这在 OP 的案例中起作用:

$('body').on('click', '.view_data', function () {
  // your code here...
});

原答案:

试试这个:

$('#datatable-default').on('click', '.view_data', function () {
  // your code here...
});

说明:

第二行的 HTML 由DataTables在点击注册后生成。详情请看jQuery Event Delegation

【讨论】:

  • 不,它不起作用。如果你能看到我的 search_details.php,我没有使用 tbody 。是你的问题吗?
  • 不,它不起作用。而且我也没有在控制台中看到任何错误。
  • 您确定使用父表的ID(按钮所在的表)
  • 另外,你能分享父表的HTML吗?
  • 这是我使用详细信息按钮打开模态窗口的父表(数据表)..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-14
  • 1970-01-01
  • 1970-01-01
  • 2018-08-30
  • 1970-01-01
  • 2015-09-30
相关资源
最近更新 更多