2013-05-01 21 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庫。