簡體   English   中英

未捕獲ReferenceError:未定義categoryID錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM