如果没有加载,从外部源加载jQuery [英] load jQuery from external source if not loaded

查看:110
本文介绍了如果没有加载,从外部源加载jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从源代码加载jQuery

我喜欢做的是放弃我的本地jquery.js并托管
别的地方。但是,如果谷歌垮台怎么办?所以
让代码成为使用其他来源的后备,如果jQuery
仍未加载...

What I like to do is to drop my local jquery.js and have it hosted somewhere else. But what if Google is down? So let's code a fallback that uses another source if jQuery is "still" not loaded...

我做了这个测试用例但是它似乎不起作用,也许
有人可以帮助我:

I made this test case but it does not seem to work, maybe someone can help me out:

http://jsfiddle.net/RBz4n

推荐答案

这很有效(来自 HTML5 Boilerplate ):

<!-- Grab Google CDN's jQuery. fall back to local if necessary -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.4.2.js"%3E%3C/script%3E'))</script>

这篇关于如果没有加载,从外部源加载jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆