多个IF语句的jQuery UI问题

时间:2010-04-29 20:56:53

标签: javascript jquery-ui-dialog

我绝对不认为自己是一个jQuery / javascript专家,但我知道足够的编程可以通过 - 但在这个项目中我遇到了一个问题,jQuery UI无法初始化第二个对话框。在初始化每个语句之前,我有2个if语句要测试,但只有第一个if语句似乎正在开始。

 $(document).ready(function(){  
  // regular dialog box
        $("#dialog").dialog({autoOpen: false, modal: true});
        $("#dialog_link").click(function(){
            $("#dialog").dialog("open");
            return false;
        });

  // confirm box
  if($.cookie("modal_confirm").length > 0 && $.cookie("modal_confirm")!="") {
   $("body").prepend(''+$.cookie("modal_confirm")+'');
   var g = $("#confirm");
   g.html( g.html().replace(/\+/g," ") );
   $("#confirm").dialog({ 
     modal: true,
     stack: true,
     buttons: {
      'OK': function() { window.location.replace($.cookie("confirmGo"))); (this).dialog('close'); },
      Cancel: function() { $(this).dialog('close'); }
     },
     close: function(){ $.cookie("modal_confirm",null); $.cookie("confirmGo",null);}
   }); 
  }

  // alert box
  if($.cookie("alert").length > 0 && $.cookie("alert")!="") {
   $("body").prepend(''+$.cookie("alert")+'');
   var f = $("#alert");
   f.html( f.html().replace(/\+/g," ") );
   $("#alert").dialog({modal: true, stack: true, buttons: {'OK': function() {$(this).dialog('close');}}, close: function(){ $.cookie("alert",null); }});
  } 
    });

在这种情况下,警报模式将在确认打开时打开。如果我在确认前移动它,那么警报将会打开,但确认无法打开。 这是一个jQuery UI问题吗?如果是,是否有解决方法?

请提前帮助和谢谢。

1 个答案:

答案 0 :(得分:1)

第18行你有一个额外的括号,后来在同一行忘记了$(前面)的$。它应该是:

'OK': function() { window.location.replace($.cookie("confirmGo")); $(this).dialog('close'); },

使用jslint找到这些错误。