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

イベント オブジェクトのクロス ブラウザー プロパティ 'target' を使用する必要があります。

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