2014-12-03 64 views
-3

我不明白爲什麼我會得到這個,下面的代碼:未捕獲的ReferenceError:jQuery是沒有定義

<head> 

      <script src="https://code.jquery.com/color/jquery.color-2.1.2.min.js" type="text/javascript"></script> 
      <script> 
       var json1 = { 
       text: "After first paragraph" 
       }; 



       var first_content_added = false; 


       $(function() { 
       $(".learn-more").on("click", function() { 
       $.getJSON("json_info.json", function(data) { 
       appendContentToFirstP(data.reviews[0].about.moreinfo); 
       }); 

       }); 
       }); 

       function appendContentToFirstP(content) { 

       if (first_content_added) { 
       return; 
       } 

       var after_first_p = $('<p class="more-info" />'); 


       after_first_p.text(content); 


       $(".first").append(after_first_p); 


       first_content_added = true; 
       } 


      </script> 
</head> 

什麼會導致錯誤? 我最初的想法是錯誤是因爲我沒有導入JQuery,但我有。它位於頂部的腳本標籤內。

+1

你不是已經包括JQuery的本身,而是另一個librarie jquery.color – 2014-12-03 13:04:12

回答

5

還沒有包括jQuery,你只包含插件jQuery.color

參考它以前 jQuery.color:

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script> 
+0

謝謝。即使當我添加這個,頁面加載後,我得到以下三個錯誤: GET文件://code.jquery.com/jquery-1.11.0.min.js網:: ERR_FILE_NOT_FOUND jquery。 color-2.1.2.min.js:2 Uncaught ReferenceError:未定義jQuery html.html:16未捕獲的ReferenceError:$未定義 – 2014-12-03 13:11:17

1

之前寫那種顏色JS這樣

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script> 
    <script src="https://code.jquery.com/color/jquery.color-2.1.2.min.js" type="text/javascript"></script> 
相關問題