[英]Uncaught ReferenceError: categoryID is not defined error
下面的代碼引發Uncaught ReferenceError:categoryID未定義錯誤,這是什么問題?
function selectCategory(obj) {
var categoryId;
categoryId=obj.getAttribute("data-category-id");
if ((document.getElementById("sCategory").value) != categoryID)
{
document.getElementById("sCategory").value = categoryID;
$.fancybox.close(".category-selection-fancybox-popup");
$.cookie("categoryId", categoryID, { expires : 360 });
$('.search').submit();
} else {
$.fancybox.close(".category-selection-fancybox-popup");
}
}
變量在javascript中區分大小寫。 實際上, JavaScript完全是區分大小寫的語言。 您已經聲明了像var categoryId;
這樣的變量var categoryId;
在你if條件使用的是資本d在變量名的結束- > != categoryID
和$.cookie("categoryId", categoryID
為好。
JavaScript是區分大小寫的語言。 因此,可能的原因是您在以下幾行中將categoryId
稱為categoryID
。
document.getElementById("sCategory").value = categoryID;
$.cookie("categoryId", categoryID, { expires : 360 });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.