【问题标题】:Proceed with redirect after dialog confirm item clicked单击对话框确认项目后继续重定向
【发布时间】:2013-09-12 19:31:53
【问题描述】:

我正在使用 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。

提前致谢。

【问题讨论】:

    标签: jquery html jquery-ui jquery-ui-dialog


    【解决方案1】:

    使用event.preventDefault()

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

    【讨论】:

      【解决方案2】:

      我在这里得到了答案:http://forum.jquery.com/topic/how-do-i-make-the-dialog-widget-modal-confirmation-redirect-to-another-site-when-i-click-one-of-the-options

      感谢您的回答。

      我将代码更改为:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多