2012-09-17 71 views
0

我使用JQuery來設置一些組合框,並且我已經在.ready函數中包裝了.combobox調用,以確保我的控件可用,但每隔10次左右加載頁面時,用於組合框的元素不在DOM中。發生了什麼事情,這怎麼可能?

我的外部JavaScript爲什麼JQuery .ready函數有時不等待DOM?

$(document).ready(function() 
{ 
    if (document.getElementById('selMinPrice')) 
    { 
     console.log('selMinPrice exists in the DOM.'); 
     console.log('selMinPrice value=' + document.getElementById('selMinPrice').value); 
    } 
    else 
    { 
     console.log('selMinPrice DOES NOT EXIST in the DOM!!!!!!!!!!!!!!!!!!!!!!!!!!'); 
    } 
    // setup min & max price comboboxes 
    $(".selMinPrice").combobox(); 
    $(".selMaxPrice").combobox(); 
    $("#toggle").click(function() 
    { 
     $(".selMinPrice").toggle(); 
     $(".selMaxPrice").toggle(); 
    }); 
}); 

我只注意到由於某種原因在IE瀏覽器的問題,但是這並不是說,它並沒有在其他瀏覽器存在。

想法?

+1

可能相關:http://stackoverflow.com/questions/1561606/document-ready-doesnt-work-in-ie – rlemon

+0

我有同樣的問題,所以我做了什麼是我用'加載'而不是'就緒'它解決了我的問題 – Linas

+3

是'selMinPrice'類或ID?您正在使用這兩個約定。另外,爲什麼在使用jQuery時使用getElementById? – Shmiddty

回答

相關問題