2014-01-23 61 views
0

我在我的頁面中使用jQuery。我導入了以下內容:爲什麼我在jQuery中遇到Uncaught類型的錯誤?

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

更改了Cookie插件的名稱,因爲我的TomCat服務器阻止了原始名稱。我在控制檯中收到以下錯誤,並且我的jQuery代碼不工作!爲什麼我看到這個?

Uncaught TypeError: Object function (selector, context) { 
    // The jQuery object is actually just the init constructor 'enhanced' 
    return new jQuery.fn.init(selector, context, rootjQuery); 
} has no method 'cookie' AlertConfiguration.jsp:92 

這是我的jQuery:

if($.cookie('remember_select') != null) { 
     $('.XCONPVAL option[value="' + $.cookie('remember_select') + '"]').attr('selected', 'selected'); 
     $('.limitemailalertvalue option[value="' + $.cookie('remember_select') + '"]').attr('selected', 'selected'); 
     $('.siteID1 option[value="' + $.cookie('remember_select') + '"]').attr('selected', 'selected'); 
     $('.groupID1 option[value="' + $.cookie('remember_select') + '"]').attr('selected', 'selected'); 
     $('.divisionID1 option[value="' + $.cookie('remember_select') + '"]').attr('selected', 'selected'); 

    } 

    $('.select_class').change(function() { 

     $.cookie('remember_select', $('.XCONPVAL option:selected').val(), { expires: 90, path: '/'}); 
     $.cookie('remember_select', $('.limitemailalertvalue option:selected').val(), { expires: 90, path: '/'}); 
     $.cookie('remember_select', $('.siteID1 option:selected').val(), { expires: 90, path: '/'}); 
     $.cookie('remember_select', $('.groupID1 option:selected').val(), { expires: 90, path: '/'}); 
     $.cookie('remember_select', $('.divisionID1 option:selected').val(), { expires: 90, path: '/'}); 

    }); 

Hierarchy這是我的文件夾層次。我有我的js文件在js文件夾中。我的JSP在jsps文件夾中。

+0

你確定你的cookie插件的路徑是正確的嗎? – Felix

+0

您的js文件'cookie.jquery.js'未正確加載,可能存在一些路徑問題。 – Jai

+0

@Felix看到我編輯的帖子。我包括我的文件夾層次結構 –

回答

0

可能是這樣的問題:在你的if

$('.groupID1 option[value="' + $.cookie('remember_select') + '"]') 
     .attr('selected', 'selected');*/ 
     ///---------------------------^^----this 

,並在您更改功能:

$.cookie('remember_select', $('.groupID1 option:selected').val(), 
      { expires: 90, path: '/'}); */ 
     ///----------------------------^^---you have this at end of this line 
+0

這是一個類型錯誤。忘了刪除評論,而張貼在這裏 –

0

爲您的文件的路徑不正確,變:

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

到:

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

因爲你index.html是相同的目錄中js文件夾。

+0

看到我編輯的問題。遇到新的錯誤。 –

+0

@AnushaHoney它是正確的文件名'cookie.jquery.js'嗎? – Felix

+0

是的。它是同一個名字。 –

相關問題