我正在尝试将一个onclick事件监听器添加到jquery datatable paginate按钮。
下面我试图检查点击的分页按钮是否有效
var table = $('#example').DataTable({
drawCallback: function(){
var pb = $('.paginate_button');
alert(JSON.stringify(pb));
$(pb,this.api().table().container()).on('click',function(){
//Logic to get which pagination button was clicked and get to know if the button was disabled .
//Something like : this.class
});
}
});
在这种情况下,如何了解事件来源。
答案 0 :(得分:1)
在下方获取点击按钮属性
$(document).ready(function (){
var table = $('#example').DataTable({
drawCallback: function(){
var pb = $('.paginate_button');
$(pb,this.api().table().container()).on('click',function(){
//Logic to get which pagination button was clicked and get to know if the button was disabled .
//Something like : this.class
alert("You have click button :" + this.text);
if ($( this ).hasClass( "disabled" )) {
alert("Button you have clicked is disable");
} else {
alert("Button you have clicked is enable");
}
});
}
});
});
还可以找到链接jsfiddle链接: