Jquery 就绪 dom

发布于 2024-10-31 02:12:34 字数 210 浏览 2 评论 0原文

我遇到了一种 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

疾风者 2024-11-07 02:12:34

如果您查看 jQuery 文档

$(function () {
    // Everything here will be called AFTER the DOM is loaded
    // So it will be called after your widget is loaded
    // but it will wait that your whole page is loaded.
});

但是现在,如果您希望 Javascript 代码为在小部件准备好后立即执行,而不是等待整个页面加载,我知道的唯一(正确)方法是通过 Javascript 和一些 DOM 操作来创建小部件。
这样做,您可以使用@Robbert 给出的代码。

然后,如果您不介意代码不好,您可以 HTML 小部件之后执行 javscript,但这是完全错误的,我不建议您这样做这样做。

<div class="widget">
    <!-- Your widget html code -->
</div>
<script>
    // your JS code
</script>

根据给出的三个解决方案,我建议您直接从 javascript 生成 Widget。这样做更好,不会造成干扰,而且您不必等待整个页面加载完毕。

If you take a look at the documentation of jQuery :

$(function () {
    // Everything here will be called AFTER the DOM is loaded
    // So it will be called after your widget is loaded
    // but it will wait that your whole page is loaded.
});

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.

<div class="widget">
    <!-- Your widget html code -->
</div>
<script>
    // your JS code
</script>

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.

一个人的夜不怕黑 2024-11-07 02:12:34

您可以在该小部件之后添加您的 JavaScript,并且没有加载事件

You could just add your javascript after that widget and don't have a load event

独﹏钓一江月 2024-11-07 02:12:34

尝试像

widget_function()

$(document).ready(

other JS
)

在 document.ready 之外执行小部件之类的操作,然后它将在您的 html 之前加载

Try something like

widget_function()

$(document).ready(

other JS
)

just do the widget outside the document.ready then it wil load before your html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文