数据表 jquery 单击事件在分页后不起作用 [英] datatables jquery click event not working after pagination

查看:35
本文介绍了数据表 jquery 单击事件在分页后不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 http://datatables.net/

<button class='btn btn-success activeAccount'>Activate Account</button>

我在onclick事件上触发ajax调用,下面是ajax调用代码:

I trigger ajax call on onclick event, below is ajax call code:

$(".activeAccount").click(function() {
  var intCounselorId = $(this).parent().parent().find('input[class="counselorId"]').attr("value");
  var intOwnerId = $(this).parent().parent().find('input[class="userID"]').attr("value");
  var strAction = 'activateAccount';
  performAction(intCounselorId, intOwnerId, strAction);
});

function performAction(intCounselorId, intOwnerId, strAction) {
  $.ajax({
      url: '/admin/counselormanagement/expertmanagementgridaction',
      data: 'intCounselorId='+intCounselorId+'&intOwnerId='+intOwnerId+'&strAction='+strAction,
      type: "POST",
      async:false,
      success: function(intFlag) {
        if(intFlag == 1){
          location.reload();
        }
      }
  });
}

我正在尝试运行一个在第一页上正常工作的 onclick 事件,但是一旦我转到第二页(或任何其他页面)它就会停止工作.

I'm trying to run an onclick event which works normally on page one, but as soon as I go to page 2 (or any other) it stops working.

我使用的是 jquery-1.10.2.min.js 和 1.9.4 版本的数据表

I'm using jquery-1.10.2.min.js and 1.9.4 version of datatable

推荐答案

因为事件仅附加到现有元素.

Because the event is attached only to existing elements.

您应该将其更改为:

$("#tableId").on("click", ".activeAccount", function(){
   // your code goes here
});

jQuery.on 的文档中阅读更多内容.

Read more in the documentation of jQuery.on.

这篇关于数据表 jquery 单击事件在分页后不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆