2

我有一个使用 jQuery DataTables ( https://datatables.net/ ) 的 HTML 表。这些行使用 html 链接呈现以删除一行。我使用下面的代码来处理链接的点击事件,删除服务器上的行,然后在前端动画删除行。

$(document).on("click", ".delete-operation", function (e) {
        e.preventDefault();
        var oTable = $('#alloperations').dataTable();
        var operationId = $(this).data('id');

        // Get the parent table row and mark it as having been selected
        // due to the fact rowindex does not work in order in datatables
        var tableRow = $(e.toElement).parents('tr').addClass('row_selected');


        bootbox.confirm("Are you sure?", function (answer) {
            if (answer) {                
                // send request to delete operation with given id.
                $.ajax({
                    type: 'delete',
                    url: "/operations/" + operationId,
                    success: function () {                       
                        var anSelected = fnGetSelected(oTable);

                       //Get all the row cells and animate a deletion
                        tableRow.children().animate({ backgroundColor: "red", color: "black" }, 300, function() {
                            tableRow.fadeOut(2000, function() {
                                oTable.fnDeleteRow(anSelected[0]);
                            });
                        });

                    },
                    error: function(result) {
                        $("#messageContainer").html(result.responseJSON.ResponseView);                       
                    }

                });
                return true;
            }
            else {
                // User clicked cancel
                return true;
            }
        });
    });

问题:这在 Chrome 中完美运行,但在 Firefox 中根本不起作用,有谁知道我如何让它在 Firefox 中也能运行?

4

1 回答 1

1

您应该使用事件对象的跨浏览器属性“目标”:

var tableRow = $(e.target).parents('tr').addClass('row_selected');
于 2013-09-19T11:00:39.320 回答