javascript 文档就绪 Firefox (jQuery)
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
document.ready
在 DOM 加载后被触发。你可以试试这个:document.ready
is fired after the DOM is loaded. You may try this:您不一定需要为此使用 jQuery。
只需有一个 onload 函数,如下所示:
或者您可以将函数调用动态附加到 onload 事件,如下所示:
您可以将 jQuery 函数调用嵌入到
JavascriptFunctionName
函数中。编辑:
jQuery 也能够通过以下代码做到这一点。我建议首先尝试这样做,以避免不必要的冗余代码。
You don't necessarily need to use jQuery for that.
Simply have an onload function as below:
Or you can dynamically attach your function call to the onload event as shown below:
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.
您可以尝试使用 head.js 之类的内容来指定执行顺序,同时仍然利用并行加载。
You can try using something like head.js to specify execution order, while still taking advantage of parallel loading.