2013-10-21 16 views
13

Ho ricevuto questo errore che dice che jQuery non è definito. Voglio usare twitter bootstrap e jQuery-UI. Nel mio <head> ho aggiunto CSS e JS necessari. Ho notato che la pagina jQuery-UI utilizza 1.9.1 jQuery e l'ultima versione è 1.10.2. Quindi presumo ci sia una sorta di conflitto in corso. Il bootstrap di Twitter richiede jQuery in modo che possa causare l'errore. O forse sto facendo qualcosa di sbagliato.jQuery non è definito twitter bootstrap

Responsabile:

<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> 

Errore:

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

enter image description here

+7

Jquery ha bisogno di essere elencati prima di bootstrap. –

+2

Perché stai includendo due versioni di jQuery? – j08691

+0

@ j08691 Bene il sito di interfaccia utente jQuery collegato per utilizzare quella versione e ho cercato alcune informazioni sulla compatibilità con le versioni precedenti di JS. Ho letto che è buono ma a volte possono esserci degli errori quindi ho incluso entrambi. – Liondancer

risposta

45

Load jQuery prima di tutto il resto! file di

<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

Carica sempre CSS prima di JS – Popnoodles

+0

@popnoodles - Thx per quello, modificato :) – tymeJV

+1

Idealmente dovresti caricare javascript dopo l'HTML così poco prima di '' - non è usato fino ad allora e accelera il caricamento della pagina in questo modo. – 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> 

add jquery js sopra bootstrap

4

Ho provato questo e questo ordine sembra funzionare al meglio.

  1. carico CSS
  2. Load jQuery
  3. carico Bootstrap
  4. Load jQuery UI
5

Questo è molto probabilmente a causa di 2 motivi:

  1. si sta caricando jQuery due volte; rimuovere uno di essi (preferibilmente la versione precedente).
  2. Si sta caricando bootstrap.min.js prima di caricare jQuery (leggere la documentazione here).

Quello che dovete fare è:

<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

Caricamento bootstrap.min.js prima che jQuery fosse il mio problema sembrerebbe. Saluti. – Icementhols