我的 jQuery 就绪函数触发得太早了...它还没有准备好!
我将可调整大小添加到作为复杂页面一部分的几个 div 标签。但是 $(document).ready() 如果执行得太早。并非所有内容都已解析并且调整大小失败。
如何让 jQuery 真正等到文档准备好?
我已经尝试过...
$(document).ready()
$(document).load()
$(window).load()
通过添加一个与这些代码相同的临时按钮,我在页面渲染后单击该按钮,我得到了正确的可调整大小的用户界面。
我正在使用 jQuery v1.4.2 和 jQuery UI v1.8.4 以及 Firefox v3.6.8。
I'm adding resizable to several div tags that are part of a complex page. But the $(document).ready() if executing too early. Not everything has been parsed and the resizable fails.
How do I get jQuery to really wait until the document is ready?
I've tried...
$(document).ready()
$(document).load()
$(window).load()
By adding a temporary button with the same code as these, that I click after the page is rendered, I get the proper resizable UI.
I'm using jQuery v1.4.2 and jQuery UI v1.8.4 with Firefox v3.6.8.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不应该是。当 DOM 被解析和渲染时,
ready()
会被触发。唯一仍然可以加载的是样式表(不知道如何处理这些)和图像。如果您的大小调整取决于图像完全加载,请使用
load
事件代替。This shouldn't be.
ready()
fires when the DOM has been parsed and rendered. The only thing that could still be loading is style sheets (don't know what to do about those) and images.If your resizable depends on images being fully loaded, use the
load
event instead.傻子应该受伤。
我还有一个 body onload 事件,该事件在 jQuery 事件之后执行,但调整大小取决于该事件。
答:不要同时使用这两种方法。
Stupid should hurt.
I also had a body onload event that was executing after the jQuery events but on which the resizable was dependent.
Answer: Don't use both methods.
尝试使用
$(window).load()
而不是$(document).ready()
...这将等到每个方面都加载完成。有点慢,但应该可以解决你的错误。Try using
$(window).load()
rather than$(document).ready()
... This will wait until EVERY single aspect has loaded to completion... a little slower but should iron out your bug