javascript - bootbox 确认 - 选择“确定”时包括 href

标签 javascript jquery html django bootbox

我正在尝试添加 bootbox.js到测试页面。

目前,当我在触发 bootbox 的超链接中包含 href 标记时,无论我单击哪个确认按钮(取消或确定),都会触发 href。

如何将 href 标签包含到 bootbox js 代码中,仅当用户选择“确定”确认选项时才触发?我尝试了多次尝试,但无济于事。

这是带有 href 标签的超链接:

<a id="id_customized_details_duplicate" href="{% url customized_details_duplicate customized_detail.id %}">Duplicate</a>

这是我的书箱 js 代码:

    $(document).ready(function(){
        $('#id_customized_details_duplicate').on('click', function(){
            bootbox.confirm("Are you sure?", function(result) {
                if (result) {
                    //include the href duplication link here?;
                    //showProgressAnimation();
                    alert('OK SELECTED');
                } else {
                    alert('CANCEL SELECTED');
                }
            });
        });
    });

最佳答案

尝试这种方式,防止 anchor 标记的默认操作,并在bootbox确认处理程序中使用相应的href位置添加窗口重定向调用(当单击“确定”选项时)。

 $(document).ready(function(){
    $('#id_customized_details_duplicate').on('click', function(event){
                   event.preventDefault();
        bootbox.confirm("Are you sure?", function(result) {
            if (result) {
                 //include the href duplication link here?;
                 window.location = $(this).attr("href");

                //showProgressAnimation();
                alert('OK SELECTED');
            } else {
                alert('CANCEL SELECTED');
            }
        });
    });
});

现场演示: http://jsfiddle.net/dreamweiver/9he30z4y/255/

快乐编码:)

关于javascript - bootbox 确认 - 选择“确定”时包括 href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23539350/

相关文章:

javascript - 2 RSS feeds inside on one webapp

javascript - Backbone .View : delegateEvents not re-binding events to subview

javascript - 当 Bootstrap 中触发两个模态时,如何关闭其中一个模态

javascript - 使用一个 for 循环的倒三 Angular 形

javascript - 从 Node.js 服务器接收 JSON 对象

jquery - .ajaxStart 和 .ajaxStop 未触发

html - CSS SVG 动画在边缘不起作用

javascript - 根据数组中填充的排序顺序对 html 进行排序

html - Bootstrap 元素下的文本

javascript - 如何从特定选择和下拉列表中获取值?