【问题标题】:jquery ui dialog is creating two dialogsjquery ui 对话框正在创建两个对话框
【发布时间】:2012-05-17 04:23:16
【问题描述】:

截图:http://d.pr/i/A4Kv

这是我的对话代码:

function popupbox(title,html,buttonTxt,buttonAction) {
  var buttons = {};
  if(buttonTxt != null) {
    buttons[buttonTxt] = buttonAction;
  }
  buttons['Cancel'] = function() {
    jQuery(this).dialog('destroy').remove();
  };
  var p = jQuery('<form class="dialoginnerbox">' + html  + '</form>');
  p.dialog({
    autoOpen: false,
    resizable: false,
    modal: false,
    width: 'auto',
    height: 'auto',
    maxHeight: 600,
    maxWidth: 980,
    title: title,
    close: function(event, ui){
        jQuery(this).dialog('destroy').remove();
    },
    buttons: buttons
  });
  p.dialog('open');
}

有什么想法吗?

---- 更新----

我将返回的 html 换成了一些虚拟文本并修复了它。所以放入弹出窗口的 html 的某些东西使它打开了两次...

【问题讨论】:

  • 我在弹出框里放了一个警报,它出现了一次。然后我在对话框的打开事件上发出警报,它出现了两次。出于某种原因,弹出框被调用一次,但正在创建两个对话框......我无法在你的小提琴上重新创建它jsfiddle.net/wtBky/1

标签: jquery-ui dialog


【解决方案1】:

格式错误的 html 和内联脚本标签导致 jquery ui 对话框打开多个对话框。

【讨论】:

    【解决方案2】:

    使用 jQueryUI 对话框;在某些情况下,jQuery 可能会将有效的 html 视为格式错误的 html。我这么说的原因是我用有效的 html 和有效的 html cmets 为我的对话框加载了 html。我得到了双对话框,直到我从 ajax 加载的 html 中删除了 html cmets。示例...

    内容.htm

    <div id="myDialogContent">Alert!</div><!-- Here is an innocent looking comment -->
    

    dialog.js

    $.get( '/content.htm', function( html ){ 
        $( html ).dialog(); 
    });
    

    这将产生一个双重对话。如果 html 以 html 注释开头或结尾,则会出现相同的对话框问题。唯一的方法是删除 html 注释或将 html 文本包装在另一个 html 标记中,就像这样......

    dialog.js

    $.get( '/content.htm', function( html ){ 
        $( '<div>'+html+'</div>' ).dialog(); 
    });
    

    这将产生一个对话框。

    【讨论】:

      【解决方案3】:

      函数 display_dialog() { if($('.dialog_wrapper').length) { 返回; }

      $('<div class="dialog_wrapper"</div>').dialog({
          autoOpen: true,
          modal: true,
      

      【讨论】:

        【解决方案4】:

        解决此问题的方法是使用计数器:

        var count = 0;
        var $dialog = $('<div></div>') .dialog({ ...
        
        autoOpen: false,
                                modal: true,
                                height: 625,
                                width: 500,
                                title: pagetitle
        ...
        });
        
        if (count > 0) {
                                $dialog.dialog("destroy").remove();
                                count = 0;
                            }
                            $dialog.dialog('open');
                            count++;
        

        为我工作...对于对话问题,但我在服务器上收到多个请求... 类似的东西:当我第一次点击链接时,它会将信息发送到服务器。当我第二次单击(不刷新浏览器)时,它会发送两次相同的信息。当我第三次点击时,向服务器发送了三个请求,以此类推……

        【讨论】:

          【解决方案5】:

          如果您将 html 包装在单个标签中,它可能会清理它。 在 html 中包含 div 可能会导致每个 div 都出现一个对话框,除非上面有一个层:

          这对我不起作用:

          <hr /> blah blah blah 
          <h3>blahblahtitle</h3> 
          <div id=somestufffirst>here's the stuff</div> 
          <div id=someotherstuff>here's some more stuff</div>
          

          但是这样做了:

          <div>
          <hr /> blah blah blah 
          <h3>blahblahtitle</h3> 
          <div id=somestufffirst>here's the stuff</div> 
          <div id=someotherstuff>here's some more stuff</div>
          </div>
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-08-20
            相关资源
            最近更新 更多