额外的jquery在数据表分页中不起作用

时间:2015-08-04 06:31:30

标签: javascript jquery datatable

我有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

1 个答案:

答案 0 :(得分: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