繁体   English   中英

数据表-jQuery在分页的数据表中不起作用

[英]Datatables - Jquery is not working in datatables in pagination

我试图在单击“ 创建测验”时提醒一些数据,它在第一页上起作用,但是在其他页面上,该警告不起作用。 我已经附上了桌子的图片

在此处输入图片说明

我试图在Google上找到,但是在数据表中对此没有任何可用的内容。

HTML代码:

<table id="post-table" class="table display-table table-striped table-
bordered" width="100%" cellspacing="0">
<thead>
<tr>
  <th>Class</th>
  <th>Published</th>
  <th>Quiz</th>
  <th>Create Quiz</th>
  <th>View Quiz</th>
</tr>
</thead>
<tbody>
<?php foreach ($allposts as $allpost) { ?>
<tr>
  <td><?php echo $grades->getGradename($allpost['grade_id']); ?></td>
  <td><?php echo $others->milliToTime($allpost['created_at']); ?></td>
  <td><?php echo $quiz->quizCount($allpost['post_id']); ?></td>
  <td>
    <a href="#" data-post-id='<?php echo $allpost['post_id']; ?>' class="create-quiz"><i class="fa fa-plus-circle" aria-hidden="true"></i></a>
  </td>
  <td><a href="/admin/quiz/allquiz.php?post_id=<?php echo $allpost['post_id'] ?>"><i class="fa fa-eye" aria-hidden="true"></i></a></td>
</tr>
<?php } ?>
</tbody>
</table>

脚本

$('#post-table').DataTable({
    "bSort": false
});

$('.create-quiz').click(function(e){
    e.preventDefault();
    alert("ss");
});

您的问题是,在页面上加载浏览器,然后执行JavaScript并将代码与首页中存在的按钮相关联。 但是当您更改页面时,看到的那些元素是没有附加任何事件侦听器的新元素。

最简单的解决方案是侦听容器元素甚至文档上的事件。 就像是:

$(document).on('click', '.create-quiz', function(){ console.log('here i am'); }

应该管用

暂无
暂无

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

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