为什么 JQuery .ready 函数有时不等待 DOM



我正在使用JQuery来设置一些组合框,并且我已经将.combobox调用包装在.ready函数中以确保我的控件可用,但是在每10次左右加载页面时,用于组合框的元素不在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中注意到了这个问题,但这并不是说其他浏览器中不存在它。

思潮?

这是一个在jQuery 1.8.0中引入并在1.8.1中修复的错误

门票: http://bugs.jquery.com/ticket/12282

在 jQuery 1.8.1 的发行说明中提到了它 http://blog.jquery.com/2012/08/30/jquery-1-8-1-released/

从 1.8.0 升级到 1.8.1 应确保在 IE 中不会过早调用 .ready。

最新更新