2013-05-01 29 views
2

什么是第二个声明,以及为什么jQuery在HTML中引用两次?HTML - 对jQuery的引用

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> 
</script> 

<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>')</script> 

回答

5

它检查是否从Google CDN加载了jQuery。如果不是,它会回落到jQuery的本地副本。

2

第二行是说像:

if (the google version of jQuery i.e. 1.7.2 is available) 
    use it 
else 
    lets include what we have in local i.e. 1.7.1 . 
0

看起来后备从谷歌服务器加载jQuery的API,第二个脚本检查,如果jQuery对象的定义,如果不是从网站的域名加载jQuery库。