Bootbox确认对话框问题 [英] Bootbox Confirm Dialog problems

查看:348
本文介绍了Bootbox确认对话框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Unfortunately, the doc Bootbox ( http://paynedigital.com/2011/11/bootbox-js-alert-confirm-dialogs-for-twitter-bootstrap ) not teach how to call the confirm dialog. As it is in the doc window always appears when the page is loaded, what is wrong, should appear when called by clicking on a delete button. This is the code that tried unsuccessfully.

// 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>

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

How do I set this bootbox to appear only when the delete button is clicked? Thanks!

编辑-解决方案:

$(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);
        }
    });
});     
});

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

Now, the deletion works when i click in "yes". I asked the developers of the plugin to put the full sample in the doc, so users do not need to create posts about how to remove the object when "yes" is clicked. Regards.

推荐答案

您可能想在此页面上基本用法"下的确认"链接上检查源代码:

You may want to check the source on the "Confirm" link under "Basic Usage" on this page: http://bootboxjs.com/

这是一个片段:

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

假设您正在使用的UI中可以使用jQuery,我将避免在锚标记中使用onClick属性.只是我的两分钱.

Assuming jQuery is available in the UI you're working on, I'd avoid using an onClick attribute in your anchor tags. Just my two cents.

这篇关于Bootbox确认对话框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆