Jquery 就绪 dom
我遇到了一种 JQuery 问题(我前几次开始),我有一个非常大的 html 页面,并且我在该页面的开头有一个小部件,但我做了一个 document.ready,所以它正在等待我的所有页面在执行之前加载,时间太长。
那么我如何在加载小部件后立即执行 jquery 呢?我尝试了类似 $(myWidget).ready() 但它不起作用
我希望我足够清楚
干杯
i got a kind of issue of JQuery ( i started few times ago), i have a very BIG html page, and i have a widget at the start of this page, but i did a document.ready so it's waiting that all my page is loaded before to execute which is too long.
So how i can execute jquery just after my widget is loaded ? i tried something like $(myWidget).ready() but it's not working
I hope i'm clear enough
CHeers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您查看 jQuery 文档:
但是现在,如果您希望 Javascript 代码为在小部件准备好后立即执行,而不是等待整个页面加载,我知道的唯一(正确)方法是通过 Javascript 和一些 DOM 操作来创建小部件。
这样做,您可以使用@Robbert 给出的代码。
然后,如果您不介意代码不好,您可以在 HTML 小部件之后执行 javscript,但这是完全错误的,我不建议您这样做这样做。
根据给出的三个解决方案,我建议您直接从 javascript 生成 Widget。这样做更好,不会造成干扰,而且您不必等待整个页面加载完毕。
If you take a look at the documentation of jQuery :
But now, if you want the Javascript code to be executed just after the widget is ready and not waiting that the whole page is loaded, the only (proper) way I know is to create the widget via Javascript with some DOM manipulation.
And doing so, you could use the code given by @Robbert.
Then, if you don't mind having a bad code, you can do the javscript just after the HTML widget, but this is awfully wrong and I don't recommend you to do that.
Based on the three solution given, I would recommend you to generate the Widget directly from javascript. It's better, not intrusive and you don't have to wait that the whole page is loaded.
您可以在该小部件之后添加您的 JavaScript,并且没有加载事件
You could just add your javascript after that widget and don't have a load event
尝试像
在 document.ready 之外执行小部件之类的操作,然后它将在您的 html 之前加载
Try something like
just do the widget outside the document.ready then it wil load before your html