1

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

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

如何将 href 标签包含到 bootbox js 代码中,仅当用户选择 OK 确认选项时才会触发?我尝试了几次尝试,但都没有成功。

这是带有 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');
                }
            });
        });
    });
4

1 回答 1

5

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

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

快乐编码:)

于 2014-05-08T10:43:15.510 回答