When I click the next page in datatables my jquery selectors aren't working anymore

夙愿已清 提交于 2019-12-13 15:05:46

问题


I'm using datatables plugin for jquery to show my data on the page. I have this selector when someone clicks on a row:

$('#myTable tr[class !="tableHeader"]').click(function(){

    alert("clicked!");

}

and everything is OK until I click on the "Next page" which shows me next 10 results - then this click function doesn't show "clicked" message box anymore no matter which row I click.

I'm guessing that the problem is in a way how these new results (rows in the table) are shown, so please give me some ideas on how to solve this.


回答1:


Use jQuery's Live function. Live will apply to all elements on the page, even ones that don't exist yet (I assume this is your issue). Thus, your new rows will be clickable when they are created and added to the DOM.

$('#myTable tr[class !="tableHeader"]').live('click', function() {
  alert("clicked!");
});


来源:https://stackoverflow.com/questions/6646505/when-i-click-the-next-page-in-datatables-my-jquery-selectors-arent-working-anym

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!