1

我不太了解如何实现bootbox.js来替换我的标准 javascript 确认警报弹出窗口,需要一些帮助。我已经阅读了一些线程和文档,但不能完全正确。

我目前有这个按钮/链接在我的模板中保存记录号:

<a href="{% url overseas_experience_details_duplicate overseas_experience_detail.id %}" onclick="if(confirmDuplicate())showProgressAnimation();else return false;">{% trans "Duplicate" %}</a>

这调用了我想用 bootbox.js 替换的当前 js 函数:

function confirmDuplicate() {
    return confirm("Are you sure?");
}

如果选中 OK 选项,则记录被复制(在复制记录时显示进度动画)。如果选择了 CANCEL 选项,则不会发生任何事情。

我已经使用以下代码来实现引导箱警报,但我不确定如何返回引导箱 OK 确认,这将复制记录。

bootbox.js

function confirmDuplicate() {
    bootbox.confirm("Are you sure?", function(result) {
    if (result == true) {

        // not too sure what to insert here to return the bootbox confirm();

    }
});

一些有效的建议将不胜感激

更新问题

我现在有启动框确认弹出显示,但我无法返回“真”或“假”确认结果。这是我的新代码:

function confirmDuplicate() {
    bootbox.confirm({
        callback: function(result) {
            if (result) {
                return result;
            }
        }
    }
}

我很沮丧,我无法返回结果来复制记录。

任何帮助都会很棒。

4

3 回答 3

3

尝试这样的事情:

<a href="whatever" onclick="return myConfirm(this.href)">....

myConfirm = function(url) {
    bootbox.confirm("sure?", function(okay) {
        if(okay)
             location.href = url;
    });
    return false;
}

您无法bootbox.confirm立即获得结果,因此false从处理程序返回以防止链接被跟踪并在回调函数中执行所需的操作。

于 2014-05-20T07:53:53.563 回答
0

继续我对您的问题的评论,这是一个不引人注目的 jquery 版本:

$('.your-link-class').on('click', function(e) {
   e.preventDefault(); //this would be equivalent to the return false in your code
   var self = this;
   bootbox.confirm("Are you sure?", function(result) {
       if (result) {
           // Here you have access to the jquery object of your link with $(self)
           // and you can do stuff like, for example:
           var clone = $(self).clone();
           clone.insertAfter($(self));
       }
    });
});

还有一个演示(不是:在演示中我使用的是传统提示,因为我没有加载引导箱源):

于 2014-05-20T07:58:40.480 回答
0
function isConfirm(message, elem) {

    bootbox.confirm(message, function (result) {
        if (result)
            window.location.href = elem;
    });

    return false;
}
<a href='@Url.Action("DeleteAction", "Admin", new { id = Model.ActionObj.id })' onclick="javascript: return isConfrm('Are you sure you want to delete this action?', this)">  Delete </a>

将此用于功能:

function isConfirm(message, elem) {
    bootbox.confirm(message, function (result) {
        if (result)
            window.location.href = elem;
    });

    return false;
}
于 2016-03-25T07:36:34.593 回答