在表单提交中实现 jQuery 确认模式? [英] Implement jQuery confirmation modal in a form submit?

查看:17
本文介绍了在表单提交中实现 jQuery 确认模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这样的 jQuery 模态确认:

I am using jQuery modal confirmation like this:

$(function() {
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      height:190,
      width: 330,
      modal: true,
      buttons: {
        "Yes": function() {
          $( this ).dialog( "close" );
        },
        No: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  });

  <div id="dialog-confirm" title="Genalytics">
  <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>Are you sure want to unshare?</p>
</div>

我有一个这样的输入按钮:

I have a input button in a form like this:

<input type="submit" value="Unshare" name="unshare" />

我想在用户点击按钮时弹出对话框.我该怎么做?

I want to popup dialog box when user clicks on the button. How can I do that?

推荐答案

需要在提交按钮所在的表单中使用提交事件.

you need to use the submit event in the form where the submit button is.

$(function() {
    var submit = false;
    $("#dialog-confirm").dialog({
      resizable: false,
      height:190,
      autoOpen: false,
      width: 330,
      modal: true,
      buttons: {
        "Yes": function() {
          $(this).dialog("close");
          submit = true;
        },
        No: function() {
          $(this).dialog("close");
        }
      }
    });

    $('form').submit(function() {
        if (!submit) {
            $("#dialog-confirm").dialog('open');
            return false;
        }
    });
});

这篇关于在表单提交中实现 jQuery 确认模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆