2013-12-16 47 views
0

我收到以下錯誤:

的ReferenceError:$ is not defined

<!doctype html> 
<html lang="en"> 

<head> 
    <meta charset="utf-8"> 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"> 
    <style> 
     #navBox { 
      width: 150px; 
      height: 150px; 
      background-color: #004C7E; 
     } 
    </style> 
    <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
    <script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
</head> 

<body> 
    <div id="navBox"></div> 
    <script> 
     $(document).click(function() { 
      $("#navBox").effect("shake"); 
     }); 
    </script> 
</body> 
</html> 

我使用了過時的jQuery的版本?我試圖按照本指南進行操作:http://api.jqueryui.com/shake-effect/

+1

您是否將其視爲本地文件?網址是否以'file://開頭? –

+0

你是否運行這個C:驅動器,所以url看起來像'file:// ...'?如果是,不要這樣做,使用Apache或IIS建立本地服務器。很簡單。 – epascarello

+1

檢查你的網絡標籤,應該很容易針對你的問題 –

回答

6

我希望如果您在Web控制檯中查看,您會看到一些404錯誤。

此:

<script src="//code.jquery.com/jquery-1.9.1.js"></script> 

...使用protocol-relative URL。這意味着如果頁面從http://example.com加載,協議將是http:;如果從https://example.com,它將是https:。關鍵是,如果它是file://c/your/stuff,那麼它是file:,並且源不存在。

使用協議相關URL是很好的,但如果你這樣做,你不能直接從本地文件系統打開HTML文件,並期望它們工作。您必須通過網絡服務器打開它們(您可以隨時在本地系統上安裝簡單的Web服務器)。

相關問題