prevent bootstrap modal window from closing on form submission

后端 未结 7 1826
轻奢々
轻奢々 2021-02-05 06:47

Hi I\'m using Bootstrap for the first time and I can\'t get my modal form to stay open on clicking the submit button. I\'ve searched SO but all related questions deal with slig

7条回答
  •  孤独总比滥情好
    2021-02-05 07:11

    Remove the following:

    data-dismiss = "modal"
    

    From the button that should not close the dialog. After that, you can close the dialog by using $( "#TheDialogID" ).modal( "hide" ). Example:

    
    
    
    

    Javascript code:

    //#region Dialogs
    function showSimpleDialog() {
      $( "#SimpleModalBox" ).modal();
    }
    
    function doSomethingBeforeClosing() {
      //Do something. For example, display a result:
      $( "#TheBodyContent" ).text( "Operation completed successfully" );
    
      //Close dialog in 3 seconds:
      setTimeout( function() { $( "#SimpleModalBox" ).modal( "hide" ) }, 3000 );
    }
    //#endregion Dialogs
    

提交回复
热议问题