2010-04-29 86 views
0

我绝对不认为自己是一个jQuery/javascript专家,但我知道有足够的编程来解决 - 但在这个项目中,我遇到了一个问题,jQuery UI无法初始化第二次对话。我有2个if语句来初始化他们每个人的面前if语句似乎被踢测试,但只有第一个。多个IF语句的jQuery UI问题

 
$(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问题吗?如果是这样,是否有解决方法?

请帮助和提前致谢。

+0

建立在@dxprog的这个答案上,你真的应该通过JSLint(http://www.jslint.com/) – PatrikAkerstrand 2010-04-29 21:10:40

回答

1

您在第18行有一个额外的括号,稍后在同一行中忘记了$(this)的前面。它应该阅读:

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

用于jslint找到这些错误。

+0

运行你所有的JavaScript哦,对不起,这就是我打开decodeURIComponent的地方,并且在原始代码I有正确数量的括号,所以这不是问题...任何其他想法? – ysquared86 2010-04-29 21:18:38