2013-10-21 35 views
13

我得到這個錯誤,說jQuery沒有定義。我想使用twitter bootstrap和jQuery-UI。在我的<head>中,我添加了必要的CSS和JS。我注意到jQuery-UI頁面使用1.9.1 jQuery,最新版本是1.10.2。所以我假設存在某種衝突。 Twitter引導程序需要jQuery,以便可能導致錯誤。或者也許我做錯了什麼。jQuery沒有定義twitter引導

頭:

<head> 
    <meta charset="utf-8" /> 
    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" /> 
    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css" /> 
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 
    <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> 
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 

</head> 

錯誤:

Uncaught ReferenceError: jQuery is not defined   bootstrap.min.js:6 
(anonymous function)         bootstrap.min.js:6 

enter image description here

+7

jQuery的需要引導之前上市。 –

+2

爲什麼包含jQuery的兩個版本? – j08691

+0

@ j08691那麼jQuery UI站點鏈接使用該版本,我查了一些關於JS向後兼容性的信息。我讀到它很好,但有時會出現錯誤,所以我同時包括這兩個。 – Liondancer

回答

45

負荷的jQuery高於一切!上述引導

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" /> 
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css" /> 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 

<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 

<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> 
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
+7

通常在加載CSS之前JS – Popnoodles

+0

@popnoodles - Thx爲此編輯:) – tymeJV

+1

理想情況下,您將在HTML之後加載JavaScript,以便在''之前加載JavaScript - 它在此之前不會被使用,它會以這種方式加快頁面加載速度。 – Popnoodles

4
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> 

附加jQuery的js文件

4

我測試過這一點,這個順序似乎工作最好的。

  1. 加載CSS
  2. 負荷的jQuery
  3. 負載引導
  4. 負荷的jQuery UI
5

這很可能是因爲兩個原因:

  1. 您正在加載jQuery兩次;刪除其中的一個(最好是舊版本)。
  2. 您在加載jQuery之前加載bootstrap.min.js(請閱讀文檔here)。

你需要做的是:

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" /> 
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css" /> 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" /> 
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js" /> 
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js" /> 
+1

在jQuery之前加載bootstrap.min.js是我看來的問題。乾杯。 – Icementhols