简体   繁体   English

在JQuery和JQuery UI之后如何加载内联脚本?

[英]How to load inline script after JQuery and JQuery UI?

I have several inline <script> tags that appear in the middle of my HTML document. 我有几个内联<script>标记显示在HTML文档的中间。 These all require Jquery, and a couple need JQuery UI. 这些都需要Jquery,还有一些需要JQuery UI。

JQuery and JQuery UI are linked at the bottom of the document. JQuery和JQuery UI在文档底部链接。

How can I have the inline scripts run after JQuery and UI are ready. 准备好JQuery和UI后,如何运行内联脚本。

I have tried wrapping the inline scripts with this with no success: 我尝试用此方法包装内联脚本没有成功:

$(window).load(function() {
//
 });

And I have also tried darbio's answer here using: 我也曾尝试darbio的答案在这里使用:

function defer(method) {
    if (window.jQuery)
        method();
    else
        setTimeout(function() { defer(method) }, 50);
}
defer(function () {
    alert("jQuery is now loaded");
});

But this didn't seem to work either? 但这似乎也不起作用?

you should load jQuery and jquery-ui in your header if you want to run jQuery inside the DOM, 如果您想在DOM中运行jQuery,则应在标头中加载jQuery和jquery-ui,

alternatively you could add window.onload() to all your script to prevent running it before the DOM is ready 或者,您可以将window.onload()添加到所有脚本中,以防止在DOM准备就绪之前运行它

src: onload src: onload

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

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