Bootbox确认对话框问题

问题描述 投票:13回答:4

不幸的是,文档Bootbox(http://paynedigital.com/2011/11/bootbox-js-alert-confirm-dialogs-for-twitter-bootstrap)没有教如何调用确认对话框。就像在doc窗口中一样,页面加载时始终会出现,这是错误的,应该通过单击删除按钮来显示。这是尝试失败的代码。

// show "false" does not work, the confirm window is showing when page is loaded.
$(function () {
bootbox.confirm("Confirm delete?", "No", "Yes", function(result) {
show: false
});     
});

// need show the confirm window when the user click in a button, how to call the confirm window?

<td><a class="icon-trash" onclick="bootbox.confirm();" href="{% url 'del_setor' setor.id %}" title="Delete"></a></td>

我如何设置该启动箱仅在单击删除按钮后才显示?谢谢!

编辑-解决方案:

$(function () {
$("a#confirm").click(function(e) {
    e.preventDefault();
    var location = $(this).attr('href');
    bootbox.confirm("Confirm exclusion?", "No", "Yes", function(confirmed) {
        if(confirmed) {
        window.location.replace(location);
        }
    });
});     
});

现在,当我单击“是”时,删除将起作用。我要求插件的开发人员将完整的示例放入文档中,因此用户无需单击“是”就可以创建有关如何删除对象的帖子。问候。

jquery twitter-bootstrap bootbox
4个回答
6
投票

您可能想在此页面上“基本用法”下的“确认”链接上检查来源:http://bootboxjs.com/

以下是代码段:

$("a.confirm").click(function(e) {
    e.preventDefault();
    bootbox.confirm("Are you sure?", function(confirmed) {
        console.log("Confirmed: "+confirmed);
    });
});

[假设您正在使用的UI中提供了jQuery,我将避免在锚标记中使用onClick属性。只有我的两分钱。


3
投票

我也需要它,但是我改变了一些东西...看看...

将此函数添加到您的全局“ jQuery Ready”函数中,如下所示:

$(document).on("click", "[data-toggle=\"confirm\"]", function (e) {
    e.preventDefault();
    var lHref = $(this).attr('href');
    var lText = this.attributes.getNamedItem("data-title") ? this.attributes.getNamedItem("data-title").value : "Are you sure?"; // If data-title is not set use default text
    bootbox.confirm(lText, function (confirmed) {
        if (confirmed) {
            //window.location.replace(lHref); // similar behavior as an HTTP redirect (DOESN'T increment browser history)
            window.location.href = lHref; // similar behavior as clicking on a link (Increments browser history)
        }
    });
});

并且只需在按钮或链接中添加一些“ data- *属性”:

<a class="btn btn-xs btn-default" data-toggle="confirm" data-title="Do you really want to delete the record 123?" href="/Controller/Delete/123"><span class="fa fa-remove"></span> </a>

所以...这样您就可以提出个性化的问题了。这对您的用户来说更加直观...

您喜欢吗?!

请参见演示:jsfiddle


0
投票
$(document).on("click", ".confirm-modal", function(e) {
    e.preventDefault();
    bootbox.confirm("Are You sure?", function(result) {
        if(result) {
            top.location.href = e.target.href;
        }
    });
});

0
投票

网格链接按钮的Aspx面:

<asp:LinkButton ID="LinkButton2" runat="server" CommandName="DELETE"  
    OnClientClick="javascript:return DeleteConfirm(this,'Are you Sure?');" CausesValidation="False" Text="Delete" > Delete
</asp:LinkButton>
    function DeleteConfirm(btn, msg) 
    { 
            if(msg==''){msg='Are You Sure ? ';}

            if ($(btn).attr('confirmOK')=='1'){return true;}

              bootbox.confirm({
                    title: 'Confirm Popup',
                    message: msg,                   
                    callback: function(result) {
                             if (result) 
                             { 
                                $(btn).attr('confirmOK', '1');
                                 btn.click();
                             }
                             else{
                               $(btn).attr('confirmOK', '0');
                             }
                    }
                });

            return false;
     };

© www.soinside.com 2019 - 2024. All rights reserved.