我在我的页面中使用jQuery。我导入了以下内容:
<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: '/'});
});
这是我的文件夹层次结构。我在js文件夹中有我的js文件。我的JSP位于jsps文件夹中。
答案 0 :(得分: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
答案 1 :(得分:0)
您的文件路径不正确,请更改为:
<script src="../js/cookie.jquery.js"></script>
为:
<script src="js/cookie.jquery.js"></script>
因为您的index.html
与js
文件夹位于同一目录。