0

我尝试让以下代码工作

//===== Dialogs =====//
$(".table a.delete").click(function (e) {
    e.preventDefault();
    bootbox.confirm("Are you sure?", function (confirmed) {
        if (confirmed) {
            var $el = $(this);
            var $tr = $el.closest('tr');
            var url = $el.closest('table').data('remove-url');
            var id = $tr.data('id');

            $tr.fadeOut(function () {
                $el.remove();
                $.post(url, { id: id }); // do the delete on the server 
            });
        }
    });
});

启动箱正在显示,但下面的代码if(confirmed)没有运行。

4

1 回答 1

2

匿名 bootbox-method 中的 $(this) 并不是指您认为它所做的事情。if (confirmed) 里面的代码被执行了,但是什么都不匹配。

$(".table a.delete").click(function (e) {
    var $el = $(this);
    e.preventDefault();

    bootbox.confirm("Are you sure?", function (confirmed) {
        if (confirmed) {
            var $tr = $el.closest('tr');
            ... etc
        }
    });
};
于 2013-01-15T13:14:13.230 回答