在HTML中包含一个js文件 [英] Inclusion of a js file in HTML
本文介绍了在HTML中包含一个js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的HTML中包含一个巨大的JavaScript文件(500K)。有没有一个聪明的方法来知道它是否已被加载。我能想到的一种方法是在其构造函数中有一个变量来初始化并通知我。加载是异步的,我不能继续下去,直到包含JS的函数。
谢谢
解决方案
通过使用jQuery,您可以处理回调函数在加载脚本文件时运行:
$。getScript(yourScriptFile.js,function(){
//在脚本加载时该怎么做
});
I am include a huge javascript file(500K) in my HTML. Is there a smart way to know if it has been loaded. One way I can think of is to have a variable in its constructor to initialize and inform me . The loading is asynchronous and I cannot proceed until function s of that JS are included.
Thanks
解决方案
By using jQuery you can handle a callback function that runs when the script file is loaded:
$.getScript("yourScriptFile.js", function(){
// What to do when the script is loaded
});
这篇关于在HTML中包含一个js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文