我正在使用引导数据表进行分页。我还在每一行添加了单击事件。但是单击事件仅在第一页中触发。排序或分页后不起作用。这是我的显示数据的 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/