【问题标题】:additional jquery not works in datatable pagination额外的 jquery 在数据表分页中不起作用
【发布时间】:2015-08-17 13:01:37
【问题描述】:

我有Datatable 和删除此数据表行的 jquery 插件

jQuery 代码:

   $(document).ready(function () {
        $(".delete-ajax").live("click", function (e) {
            e.preventDefault();
            recordId = $(this).attr('id');
            alert(recordId);
            var requestAdress = '{!! route("admin.area.cities.destroy", ":id") !!}';
            requestAdress = requestAdress.replace(':id', recordId);
            $.ajax({
                cache: false,
                dataType: "json",
                type: "delete"
                , url: requestAdress
                , date: {
                    "_token": "{{ csrf_token() }}",
                    "id": recordId
                },
                success: function () {
                    $('tr#' + recordId).fadeOut(300, 'linear');
                }
            }, "json");

            });
 });

代码工作正常,但每当我在datatable 分页 jquery 插件中更改页面时。此点击不再起作用。

数据表网站:http://datatables.net

【问题讨论】:

  • 不使用 $(document).ready 函数怎么样。触发分页的事件呢?

标签: javascript jquery datatable


【解决方案1】:

.live() 的使用现在已被贬低。使用事件委托:

$(document).ready(function () {
        $(document).on("click",".delete-ajax", function (e) { // updated ths line
            e.preventDefault();
            recordId = $(this).attr('id');
            alert(recordId);
            var requestAdress = '{!! route("admin.area.cities.destroy", ":id") !!}';
            requestAdress = requestAdress.replace(':id', recordId);
            $.ajax({
                cache: false,
                dataType: "json",
                type: "delete"
                , url: requestAdress
                , date: {
                    "_token": "{{ csrf_token() }}",
                    "id": recordId
                },
                success: function () {
                    $('tr#' + recordId).fadeOut(300, 'linear');
                }
            }, "json");

            });
 });

查看Live Removed

【讨论】:

    猜你喜欢
    • 2018-06-15
    • 2017-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-28
    • 2016-01-11
    相关资源
    最近更新 更多