数据表jquery点击事件在分页后不起作用 [英] datatables jquery click event not working after pagination
本文介绍了数据表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事件,但是一旦我转到第2页(或任何其他),它就会停止工作。
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 。
这篇关于数据表jquery点击事件在分页后不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文