简体   繁体   English

从第二页的JQuery数据表中无法识别JQuery onclick事件

[英]JQuery onclick event isn't recognizing in JQuery datatable from second page

I have JQuery Datatable and I want to delete row, when delete link is clicked. 我有JQuery Datatable,单击删除链接后想删除行。 It's working fine for first 10 rows, ie for the first page. 前十行(即第一页)运行正常。 When I move to any another from the pagination. 当我从分页移动到另一个。 It's not working. 没用 Here is my code: 这是我的代码:

$("#example tbody td.delete").click(function(event) {
                var row = $(this).closest("tr").get(0);
                oTable.fnDeleteRow( row );
    });

All last td of a row has class "delete". 一行的所有最后td都具有“删除”类。

What should I do to work for all the pages or for all the records? 我应该怎么做才能处理所有页面或所有记录?

If you're using jQuery 1.7 or older, you'll need to use the live event handler instead, as subsequent pages are added dynamically. 如果您使用的是jQuery 1.7或更早版本,则需要使用实时事件处理程序,因为后续页面是动态添加的。

$('#example tbody td.delete').live('click', function(event) {
    var row = $(this).closest('tr').get(0);
    oTable.fnDeleteRow( row );
});

jQuery .live() jQuery .live()

EDIT: 编辑:

It looks like people are still using this answer, so to update it with the latest best practices, DO NOT use .live(). 似乎人们仍在使用此答案,因此,请使用最新的最佳实践更新它, 请勿使用.live()。 Live was deprecated in 1.7 and removed in 1.9 . Live在1.7中已弃用, 在1.9中删除 Instead, use the .on() handler. 而是使用.on()处理函数。 This can handle delegated events by binding the event to a parent element, and using the actual element you want to target as the optional selector parameter. 通过将事件绑定到父元素,并将您要定位的实际元素用作可选的选择器参数,可以处理委托事件。 To put it to use in the above example, it would look like so: 要在上面的示例中使用它,它将看起来像这样:

$('#example tbody').on('click', 'td.delete', function(event) {
    var row = $(this).closest('tr').get(0);
    oTable.fnDeleteRow( row );
});

当尝试绑定内联事件时我坚持了你的想法

 onclick="$('#dataConfirmOK').attr('href',$(this).attr('url'))"

If live extension is not working then you can add live extension plugin additionaly. 如果实时扩展无法正常工作,则可以添加实时扩展插件。 http://plugins.jquery.com/files/live-extension.js_4.txt http://plugins.jquery.com/files/live-extension.js_4.txt

It is preferable if you bind the "Click event" of next page items when they load. 最好在加载下一页项目时绑定它们的“ Click事件”。 Please load the code below in each time the page load. 每次加载页面时,请加载以下代码。 and also define the function "click_function_to_call". 并定义函数“ click_function_to_call”。

<script type="application/javascript">
  $("#example tbody td.delete").click(click_function_to_call);
</script>

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

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