我在我的頁面中使用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: '/'});
});
這是我的文件夾層次。我有我的js文件在js文件夾中。我的JSP在jsps文件夾中。
你確定你的cookie插件的路徑是正確的嗎? – Felix
您的js文件'cookie.jquery.js'未正確加載,可能存在一些路徑問題。 – Jai
@Felix看到我編輯的帖子。我包括我的文件夾層次結構 –