2012-10-15 63 views
1
<html> 
<head><title>test</title> 

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"> 
    </script> 
    <!-- ERROR IS HERE the jquery is not being loaded --> 

    <script type="text/javascript" src="js/jquery.prettyPhoto.js"> 
    </script> 
    <link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" 
     media="screen" charset="utf-8" /> 
</head> 
<body> 
    <a title="Despicable Me" rel="prettyPhoto[movies]" 
    href="http://trailers.apple.com/mymovie.mov?width=640&height=360"> 
    <img src="images/thumbnails/quicktime-logo.gif" alt="Despicable Me" 
    width="50" /> 
    </a> 
    <a title="Despicable Me" rel="prettyPhoto[movies]" 
    href="ai.mov?width=640&height=360"> 
    <img src="images/thumbnails/quicktime-logo.gif" 
     alt="Despicable Me" width="50" /> 
    </a> 
    <script type="text/javascript" charset="utf-8"> 
    $(document).ready(function(){ 
     $("a[rel^='prettyPhoto']").prettyPhoto(); 
    }); 
    </script> 
</body> 
</html> 

當我打開這個網站在Firefox中,錯誤控制檯會返回一個錯誤:JavaScript錯誤:jQuery是沒有定義

jQuery is not defined. 

的HTML文件,js文件,以及CSS文件都在同一文件夾。我究竟做錯了什麼?

+0

究竟是什麼src =「// ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js」路徑 –

+2

檢查chrome中的網絡標籤以查看jquery是否正在下載正確 –

+0

jquery路徑是錯誤的。沒什麼嚴肅的,寒意 – defau1t

回答

6

得到JQuery的文件,我想你在本地運行此。 (注:不是指本地主機,意味着你打開本地的HTML文件

如果您在本地運行,那麼//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js意味着file:///ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js

所以你需要指定http://

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

但一旦你把你的頁面上傳到服務器上,沒關係,只需要//,這是最好的做法。

+0

@upvoter,因爲它的本地主機也 –

+0

@智慧我不是指本地主機,我的意思是你運行的HTML本地文件。 – xdazz

+0

@xdazz我的歉意,以爲你只是建議像其他人一樣加入'http:'。在你編輯之後,我看到你在說什麼,在web服務器之外訪問它將使用'file:'協議,它不適合讀取腳本。 – GenericJon

5

對不起最後的答案是從谷歌錯誤

嘗試下載jQuery和使用它從本地服務器就像

<script src="jquery.min.js"></script> 

如果所有文件都是同一個目錄下,然後當你追加js/在jquery.prettyPhoto.js的前面,還有css/ 它們應該像

<html> 
<head> 
<title>test</title> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
<script type="text/javascript" src="jquery.prettyPhoto.js"></script> 
<link rel="stylesheet" href="prettyPhoto.css" type="text/css" media="screen" charset="utf-8" /> 
</head> 
<body> 
<a title="Despicable Me" rel="prettyPhoto[movies]" href="http://trailers.apple.com/movies/universal/despicableme/despicableme-tlr1_r640s.mov?width=640&height=360"><img  src="quicktime-logo.gif" alt="Despicable Me" width="50" /></a> 
<a title="Despicable Me" rel="prettyPhoto[movies]" href="ai.mov?width=640&height=360"><img src="quicktime-logo.gif" alt="Despicable Me" width="50" /> </a> 

<script type="text/javascript" charset="utf-8"> 
$(document).ready(function(){ 
    $("a[rel^='prettyPhoto']").prettyPhoto(); 
}); 
</script> 
</body> 
</html> 
0

使用

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

從谷歌服務器

相關問題