jquery - 在引导数据表中分页后未触发行单击事件

标签 jquery datatable twitter-bootstrap-3

我正在使用引导数据表进行分页。我还在每一行添加了单击事件。但是单击事件仅在第一页中触发。排序或分页后不起作用。这是我的显示数据的 php 代码

        <table id='tblCustomers' class='table table-bordered table-striped'>
                                 <thead>
                                  <tr>
                                              <th>Customer id</th>
                                               <th>Company</th>
                                              <th>First name</th>
                                              <th>Last name</th>
                                              <th>Email</th>
                                              <th>Last login</th>
                                              <th>No Of logins </th>
                                   </tr>
                                  </thead>
                                 <tbody>";
                                foreach ($this->result as $row) {
                                    echo "<tr>
                                            <td>{$row['customerid']} </td>
                                            <td>{$row['company']} </td>
                                            <td>{$row['firstname']} </td>
                                            <td>{$row['lastname']} </td>
                                            <td>{$row['email']} </td>
                                            <td>{$row['lastlogin']} </td>
                                            <td>{$row['count']}</td>
                                          </tr>";

                                     }
                                  echo "</tbody></table>"; 

jquery 代码是

                        $(function () {
                         $("#tblCustomers").dataTable();
                         $("#tblCustomers tr").click(function(){
                         alert($(this).find('td:first').text());
                         });
                       });

最佳答案

将代码更改为以下。这是电话Event Delegation

    $(function () {
           $("#tblCustomers").dataTable();
           $(document).on('click',"#tblCustomers tr",function(){
                     alert($(this).find('td:first').text());
           });
    });

关于jquery - 在引导数据表中分页后未触发行单击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29119108/

相关文章:

javascript - Eclipse JavaScript 自动完成

javascript - 没有 jQuery 的 CSS 和 javaScript 幻灯片动画,类似于 jQuery Cycle 2?

jquery - Bootstrap Accordion + 数据表

html - 无法很好地定位到中心

css - Bootstrap 中的突破容器

javascript - 有没有办法将这个 jquery 代码转换为 javascript?

jquery - 将鼠标悬停在表数据上

LINQ to DataSet 不区分大小写的分组依据

javascript - 数据表不工作

javascript - 如何在侧边栏上保持图像垂直