简体   繁体   English

将window.load“加载”到文档中会不会有问题?准备好了吗?

[英]will there be an issue to have window.load 'within' a document.ready?

i just wondering is there any performance issue or anything thing wrong if that a $(window).load(), is set within a $(document).ready() 我只是想知道如果在$(document).ready()中设置了$(window).load(),是否存在任何性能问题或任何错误呢?

due to some element only can be determined after window is loaded such as dynamic size of an inline div or image, with height:auto, while 80% of the function should start working on document.ready. 由于某些元素,只有在加载窗口后才能确定,例如,行内div或图像的动态尺寸,带有height:auto,而该功能的80%应该开始对document.ready起作用。

Nopes, no issues. 不,没有问题。

[Quote] This works fine and is an acceptable practice. [报价]这很好,并且是可以接受的做法。 After all, as you describe, there may be cases where the logic in the $(window).load() handler depends on work taking place after the DOM is ready. 毕竟,正如您所描述的,在某些情况下,$(window).load()处理程序中的逻辑取决于在DOM准备好后进行的工作。 If the window is in fact already loaded by the time you set up $(window).load(), the handler will just fire immediately. 如果实际上在设置$(window).load()时窗口已被加载,则处理程序将立即触发。 [UnQuote] [取消报价]

"$(document).ready() runs as soon as the DOM has loaded, but $(window).load() will not run until the DOM has loaded AND all dom resources have loaded (like images and CSS files and stuff). That means that $(document).ready() will run before you set the value." “ $(document).ready()会在DOM加载后立即运行,但是$(window).load()在DOM加载并且所有dom资源都已加载之前不会运行(例如图像,CSS文件和内容) 。这意味着$(document).ready()将在设置值之前运行。” read more here 在这里阅读更多

window load inside a document ready? 窗口加载到文档里面准备好了吗?

Hope this helps for your understanding you can always read more in Jquery documentations. 希望这有助于您的理解,您可以随时在Jquery文档中阅读更多内容。

cheers! 干杯!

No. No issue with that at all. 不,完全没有问题。

You're just assigning an event handler to an event, which of course, will fire some time after DOMContentLoaded . 您只是将一个事件处理程序分配给一个事件,这当然会在DOMContentLoaded之后触发一段时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM