Implement jQuery confirmation modal in a form submit?

拜拜、爱过 提交于 2019-12-02 11:32:43

问题


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?


回答1:


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



回答2:


I have created Model popup by own no third party plugin.

Could you please try given link.

<input type="button" id="btnShowSimple" value="Simple Dialog" />
<input type="button" id="btnShowModal" value="Modal Dialog" />

See Demo

Hope it likes you.



来源:https://stackoverflow.com/questions/17037634/implement-jquery-confirmation-modal-in-a-form-submit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!