【发布时间】:2012-09-18 01:20:09
【问题描述】:
我正在使用 JQuery 来设置一些组合框,并且我已经将 .combobox 调用包装在 .ready 函数中以确保我的控件可用,但是在每 10 次左右加载页面时,用于组合框不在 DOM 中。发生了什么事,这怎么可能?
我的外部 javascript
$(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 中的问题,但这并不是说它在其他浏览器中不存在。
想法?
【问题讨论】:
-
selMinPrice是类还是 id?您正在使用这两种约定。另外,为什么在使用 jQuery 时使用 getElementById? -
注释掉或删除 console.log 语句。 IE 让他们窒息。
-
@j08691 - 如果控制台没有显示,IE 只会阻塞,所以我在启动时将它附加到 IE 窗口,这样就可以了。日志语句仅用于调试,没有它们仍然会出现问题。
-
您使用的是什么版本的 jQuery?有一个与 .ready() 在 IE 中过早触发有关的错误,已在 1.8.1 中修复
标签: jquery document-ready domready