的JavaScriptcookie檢查不是由輸入值工作
var dc = document.cookie;
var nv = dc.split('; ');
var cookie = new Object();
for(i = 0; i < nv.length; i++){
eq = nv[i].indexOf('=');
cookie[nv[i].substring(0, eq)] = unescape(nv[i].substring(eq + 1));
}
// type 1
//this check is working
if(cookie['name']){
alert(document.cookie);
alert("this is avaliable");
}else{
alert(document.cookie);
alert("this is not avaliable");
};
// type 2
//this check is not working error undefined;
function checkGroup(cn_name){
document.cookie = cn_name;
alert(cookie[cn_name]);
};
我使用cookie[]
檢查是我的cookie avaliable,1型檢查工作,因爲我輸入廠的文本,但2型我試圖用價值在我的cookie[]
,它沒有工作。
如何讓它工作?
我對鉻測試。 – user3233074
我不這麼認爲,它checkGroup它返回我的undefined,你能幫我檢查一下嗎? – user3233074