0

我正在使用 jQuery 对话框来确认链接单击,但不知何故,对话框在继续使用默认事件处理程序之前不会等待正确的确认。我错过了什么?

这是我的代码:

jQuery(function($) {
    $( "#dialog-submit-vp-confirm" ).dialog({
        autoOpen: false,
        resizable: false,
        modal: true,
        buttons: {
            "Submit to VP": function() {
                // Proceed with click here
            },
            Cancel: function() {
                $(this).dialog( "close" );
                return false;
            }
        }
    });

    $("#submit_to_vp").click(function(e) {
        $( "#dialog-submit-vp-confirm" ).dialog("open");
    });
});

HTML

<div id="dialog-submit-vp-confirm" title="Submit to your VP">
    <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>Your plan will now be submitted to your VP. Are you sure you want to proceed?</p>
</div>
<a href="' . JURI::root() . 'api/submit_plan.php?plan_id=' . $plan_id . '" class="btn button" style="float: right;" id="submit_to_vp">Submit to VP</a>

请忽略 HTML 中的任何 PHP/Joomla。

提前致谢。

4

2 回答 2

0

使用event.preventDefault()

 $("#submit_to_vp").click(function(e) {
     e.preventDefault();
     $( "#dialog-submit-vp-confirm" ).dialog("open");
 });
于 2013-09-12T11:24:43.463 回答
0

我在这里得到了答案:http: //forum.jquery.com/topic/how-do-i-make-the-dialog-widget-modal-confirmation-redirect-to-another-site-when-i-单击一个选项

感谢您的回答。

我将代码更改为:

jQuery(function($) {
    var href = "";

    $( "#dialog-submit-vp-confirm" ).dialog({
        autoOpen: false,
        resizable: false,
        modal: true,
        buttons: {
            "Submit to VP": function() {
                // Proceed with click here
                location = href;
            },
            Cancel: function() {
                $(this).dialog( "close" );
            }
        }
    });

    $("#submit_to_vp").click(function(e) {
        href=this.href;
        $("#dialog-submit-vp-confirm").dialog("open");
        return false;
    });
});
于 2013-09-12T11:31:53.507 回答