想要在 jQuery 后在页面刷新时出现在子对话框中

Want to be on Child Dialog on Page Refresh in jQuery

这是我的工作代码:

Working fiddle

 var dialog = $( "#dialog" ).dialog({
      autoOpen: false,
      modal: true,
      buttons: {
        Add: function() {
          addTab();
          $( this ).dialog( "close" );
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      },
      close: function() {
        form[ 0 ].reset();
      }
    });

当我单击“添加”选项卡时,它会显示一个 jQuery 对话框,但在刷新页面时我看不到该对话框。

我想保留 jQuery 页面刷新对话框。

遇到这种情况怎么办?

您可以使用 sessionStorage 来实现此目的,如下所示(我只是在此处包括了代码的必需部分):-

$(function() { 

var dialog = $( "#dialog" ).dialog({
  autoOpen: false,
  modal: true,
  buttons: {
    Add: function() {
      addTab();
      $( this ).dialog( "close" );
        sessionStorage.setItem('flag','F') //set sessionStorage item to F
    },
    Cancel: function() {
      $( this ).dialog( "close" );
        sessionStorage.setItem('flag','F') //set sessionStorage item to F
    }
  },
  close: function() {
    form[ 0 ].reset();
      sessionStorage.setItem('flag','F') //set sessionStorage item to F
  }
});

if(sessionStorage.getItem('flag') == 'T') 
{
   dialog.dialog( "open" ); // if sessionstorage's flag is T then open the dialog on page load
}

// addTab button: just opens the dialog
$( "#add_tab" )
  .button()
  .click(function() {
    dialog.dialog( "open" );
      sessionStorage.setItem('flag','T')  // set sessionStorage item to T
  });

 $( "#add_tab_link" ).click(function(e) {
    e.preventDefault();
    //alert('clicked');
    dialog.dialog( "open" );
    sessionStorage.setItem('flag','T')  // set sessionStorage item to T
  });
});

Working Fiddle