模态它多次打开

时间:2016-12-19 14:08:41

标签: javascript asp.net-mvc twitter-bootstrap bootbox

我正在使用bootbox库。我有一个名为Delete的按钮。

$('body').on("click", ".deleteDiagnostic", function () {
        var id = $(this).attr("data-diagnosticID");
        var currentRow = $(this).closest('tr');
        bootbox.confirm("Are you sure want to delete?", function (result) {
            if (result == true) {
                //code here
            }
        });
});

我也在使用PartialView,并且动态加载包含按钮的页面。有时当我点击时,bootbox会多次打开,我不知道为什么。

PS:当我第一次加载PartialView时它运行正常,但当我多次加载PartialView时,bootbox点击button多次出现。< / p>

1 个答案:

答案 0 :(得分:1)

请尝试修改您的代码:

$('body').on("click", ".deleteDiagnostic", function (evt) {
    evt.stopImmediatePropagation();

    var id = $(this).attr("data-diagnosticID");
    var currentRow = $(this).closest('tr');
    bootbox.confirm("Are you sure want to delete?", function (result) {
        if (result == true) {
            //code here
        }
    });
});
相关问题