javascript 文档就绪 Firefox (jQuery)

发布于 2024-08-13 09:44:48 字数 389 浏览 2 评论 0原文

在 FireFox 中,我在主体末尾有这个 jQuery:

$(document).ready(function() {
     $.getScript('LiveMapsJavascriptProvider.aspx?type=reference&value=6', init);
});

头部有很多 js 文件,需要全部加载才能工作。所以我将调用放入 document.ready 事件中。这不起作用。 IE 运行良好。

如果我发出警报('');在我调用 $.getScript 之前它就起作用了。

看起来像是脚本尚未加载的问题?

我认为 Document.ready 在所有脚本加载并准备就绪后被触发。

谢谢, 伊安

In FireFox I have this jQuery at the end of the body:

$(document).ready(function() {
     $.getScript('LiveMapsJavascriptProvider.aspx?type=reference&value=6', init);
});

There are a lot of js files in the head that are needed to be all loaded before this would work. So I put my call in a document.ready event. It doesn't work. IE works fine.

If I put an alert(''); before I call $.getScript it works.

It looks like a problem with the scripts not getting loaded yet?

I thought Document.ready was fired after all the scripts are loaded and ready to go.

Thanks,
ian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

岁月苍老的讽刺 2024-08-20 09:44:48

document.ready 在 DOM 加载后被触发。你可以试试这个:

$(window).load(function() {
    // will execute once all scripts and images are finished loading
});

document.ready is fired after the DOM is loaded. You may try this:

$(window).load(function() {
    // will execute once all scripts and images are finished loading
});
缪败 2024-08-20 09:44:48

您不一定需要为此使用 jQuery。

只需有一个 onload 函数,如下所示:

<body onload="JavascriptFunctionName">

或者您可以将函数调用动态附加到 onload 事件,如下所示:

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
addEvent(window, 'load', JavascriptFunctionName);

您可以将 jQuery 函数调用嵌入到 JavascriptFunctionName 函数中。

编辑

jQuery 也能够通过以下代码做到这一点。我建议首先尝试这样做,以避免不必要的冗余代码。

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

You don't necessarily need to use jQuery for that.

Simply have an onload function as below:

<body onload="JavascriptFunctionName">

Or you can dynamically attach your function call to the onload event as shown below:

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
addEvent(window, 'load', JavascriptFunctionName);

You may embed jQuery functions calls inside the JavascriptFunctionName function.

EDIT:

jQuery is also capable of doing that through the following code. I recommend trying that first, for the sake of avoiding unnecessary redundant code.

$(window).load(function() {
    JavascriptFunctionName();
});
薄荷港 2024-08-20 09:44:48

您可以尝试使用 head.js 之类的内容来指定执行顺序,同时仍然利用并行加载。

You can try using something like head.js to specify execution order, while still taking advantage of parallel loading.

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