2014-01-23 62 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

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

相关问题