【问题标题】:JQuery dialog not opening second time on clickJQuery对话框没有在点击时第二次打开
【发布时间】:2016-01-21 08:08:37
【问题描述】:

这是我打开 jquery 对话框的代码。它第一次工作(打开)但不是第二次(不打开)。一个类似的问题被问到here 但这对我不起作用

function LoadGridView(id, row) {
  var dlg = jQuery('#Edit').load('Edit.aspx');

  dlg.dialog({
    autoOpen: false,
    modal: true,
    show: 'slide',
    close: 'slide',
    width: 400,
    height: 160,
    buttons: {
      "cancel": function() {
        dlg.dialog("close");
      }
    }
  });
  

  dlg.dialog("open");
}

【问题讨论】:

    标签: jquery jquery-ui webforms


    【解决方案1】:

    你的dlg作用域在你第二次打开时不存在,你需要全局存储

    // global var to hold dlg
    var dlg;
    
    $(document).ready(function() {
    
     // get element and store it in dlg global var so that its scope may retain
      dlg = $("[id$='Edit']");
    
    
      dlg.dialog({
        autoOpen: false,
        modal: true,
        show: 'slide',
        close: 'slide',
        width: 400,
        height: 160,
        buttons: {
          "cancel": function() {
            dlg.dialog("close");
          }
        }
      });
    
    });
    

    【讨论】:

    • 哦,我的错,我搞砸了范围:(这完美地解决了我的问题。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    相关资源
    最近更新 更多