쿠키가 설정된 경우 환영 메시지를 표시하는 간단한 프로그램을 만들려고했는데 쿠키가 설정되지 않은 경우 사용자 이름을 묻는 메시지 상자가 표시됩니다.쿠키가 설정된 경우 시작 메시지 표시
작동하지 않으며 이유를 모르겠습니다. 아무도 코드에서 문제가 어디 있는지 말해 줄 수 있습니까? 코드에서이 오류가있어
<!DOCTYPE html>
<html>
<head>
<script>
function setCookie(c_name,value,expiredays){
var exdate = new Date();
exdate.setDate(exdate.getDate()+expiredays);
if(expiredays==null)
document.cookie = c_name + "=" + escape(value) +"";
else
document.cookie = c_name + "=" + escape(value) + ";expires="
+exdate.toGMTString());
}
function getCookie(c_name){
if(document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if(c_start!=-1)
c_start=c_start + c_name.length +1;
//index of the value's end
c_end=document.cookie.indexOf(";",c_start);
if(c_end==-1)//if it's the last cookie
c_end = document.cookie.length;
return unescape (document.cookie.substring(c_start,c_end));
}
}
return "";
}
function checkCookie(){
username=getCookie('username');
if(username!=null && username!="")
alert('welcome again ' + username+ '!');
else {
username=prompt('please enter your name:',"");
if(username!=null && username!="")
setCookie('username',username,365);
}
}
</script>
</head>
<body onload="checkCookie()">
</body>
</html>
http://jsbin.com/AcanusA/12/edit
jsbin-tab "console"을 체크 아웃 했습니까? "예기치 않은 토큰)", "checkCookie가 정의되지 않았습니다" –
왜 checkCookies가 정의되지 않았습니까? – Ohad
@ Shiran 콘솔에 나와 있습니다! – Cilan