2010-04-29 79 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