检查是否加载了javascript文件 [英] Check if javascript file was loaded
问题描述
我从CDN加载以下javascript文件。有什么方法可以检查这些是否已正确加载,如果没有,从本地文件夹加载它们?
I am loading the following javascript files from a CDN. Is there any way I can check if these have been loaded correctly and if not, load them from a local folder?
http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js
http:// ajax。 microsoft.com/ajax/jquery.ui/1.8.5/jquery-ui.min.js
http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js
我知道我可以检查jquery文件,但不确定其他文件。任何提示?
I know I can check the jquery file but not sure about the others. Any tips?
推荐答案
在您的HTML中,您可以执行以下操作:
In your HTML, you can do something like this:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>!window.jQuery && document.write('<script src="js/jquery-1.4.2.min.js"><\/script>')</script>
显示的示例是从Google CDN加载jquery,如果失败则返回到JQuery的本地副本。
The example shown is loading jquery from Google CDN and falls back on a local copy of JQuery if that fails.
HTML5 Boilerplate 用于展示技巧的信用
这篇关于检查是否加载了javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!