0
小提琴是here校驗值,但顯示未定義
我在下面的結構localStorage.COMMENT_DESCRIPTION.list_no
增加值,但它始終顯示未定義。
但是,當我打印到console.log它顯示的數據。問題是,當我與條件檢查它不工作
var comment_description = {};
$("#add_list_img").click(function()
{
if(localStorage.COMMENT_DESCRIPTION)
{
alert(localStorage.COMMENT_DESCRIPTION.list_no); # Here is the problem. I have added the value but the variable is empty
if(localStorage.COMMENT_DESCRIPTION.list_no == undefined)
{
alert("Here so");
cart_val = localStorage.COMMENT_DESCRIPTION.list_no || 1;
comment_description.list_no = cart_val+1;
console.log(comment_description);
storage();
}
else
{
alert("here");
cart_val = comment_description.list_no;
comment_description.list_no = cart_val+1;
storage();
}
}
else
{
cart_val = 1;
comment_description.list_no = cart_val+1;
storage();
}
});
function storage()
{
if(localStorage.COMMENT_DESCRIPTION)
{
var oldItems = JSON.parse(localStorage.getItem('COMMENT_DESCRIPTION'));
console.log("strogae "+comment_description.list_no);
var newItems = $.extend({}, oldItems, comment_description);
localStorage.setItem('COMMENT_DESCRIPTION',JSON.stringify(newItems));
}
else
{
var lc_no = {"list_no":1,"card_no":1};
var newItems = $.extend({},comment_description);
localStorage.setItem('COMMENT_DESCRIPTION',JSON.stringify(newItems));
}
console.log("added following"+localStorage.COMMENT_DESCRIPTION);
}
'localStorage.COMMENT_DESCRIPTION'是一個JSON字符串。你需要先解析它。 – Xufox