是否有可能等到所有javascript文件都被加载后再执行javascript代码? [英] Is it possible to wait until all javascript files are loaded before executing javascript code?
问题描述
我们在母版页的底部加载了几个JavaScript文件。但是,我有一种情况,我需要在加载其他脚本之前执行一些JavaScript。是否可以等到加载所有JavaScript文件然后执行一些JavaScript代码?
We have several JavaScript files which we load at the bottom of the master page. However, I have the situation that I need to perform some JavaScript before the other scripts are loaded. Is it possible to wait till all the JavaScript files are loaded and then execute some JavaScript code?
我想 $(文件).ready()
这样做了,但事实证明,事实并非如此。当然我们可以将脚本文件从底部移到顶部,但我想知道它是否可能是我想要的。
I thought $(document).ready()
did this, but as it turns out, it doesn't. Of course we can move the script files from the bottom to the top, but I am wondering if it's possible what I want.
推荐答案
你可以使用
$(window).on('load', function() {
// your code here
});
这将等到页面加载完毕。 $(document).ready()
等待DOM加载
Which will wait until the page is loaded. $(document).ready()
waits until the DOM is loaded
这篇关于是否有可能等到所有javascript文件都被加载后再执行javascript代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!