【问题标题】:bootbox confirm - include href when OK is selectedbootbox 确认 - 选择 OK 时包含 href
【发布时间】:2014-05-08 10:37:07
【问题描述】:

我正在尝试将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');
                }
            });
        });
    });

【问题讨论】:

    标签: javascript jquery html django bootbox


    【解决方案1】:

    尝试这种方式,防止anchor tag 的默认操作并在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/

    快乐编码:)

    【讨论】:

    • 感谢您的代码,但我已经修改了几个小时,因为 window.location = $(this).attr("href");代码行似乎不起作用。有什么建议吗?
    • @user1261774: 你能创建一个 jsfiddle,我会在那里检查一下
    • @user1261774:它在此处按预期工作,jsfiddle.net/dreamweiver/gvK5t
    • 感谢您的帮助。我现在可以工作了 - 感谢您的 jfiddle。
    • @JoshYates1980:不知道为什么 jsfiddle 链接坏了,但无论如何我现在已经修复了。 jsfiddle.net/dreamweiver/9he30z4y/255。谢谢你让我知道:)
    猜你喜欢
    • 2017-02-22
    • 1970-01-01
    • 2016-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    • 2018-05-08
    • 1970-01-01
    相关资源
    最近更新 更多