자바 스크립트 쿠키를 연구 중입니다. 처음 사용자 입력 자신의 번호가 365자바 스크립트 쿠키 처리
사용자의 방문을 다시 내 사이트 그/그녀 돈에 쿠키 이름, 값 및 만료 날짜를 저장할 때 기본적으로 내가 원하는
입니다 쿠키가 아직 살아 있거나 브라우저에서 아직 삭제하지 않은 상태에서 더 이상 전화 번호를 입력하지 않으면 그 사람이 내 홈페이지로 리디렉션됩니다.
여기에 지금까지 자바 스크립트에 내 코드입니다 :
function checkCookie() {
var mob_tel=getCookie("mob_tel");
if (mob_tel!=null && mob_tel!="") {
alert("Welcome again " + mob_tel);
} else {
set_name("");
}
}
function set_name(form) {
var mob_tel = form.mobtel.value
if (mob_tel != "") {
if (confirm("Are you sure you want this saved as your number?")) {
setCookie ("mob_tel", mob_tel, 365);
//window.history.go(0);
}
} else alert("Geez, at least enter something, entering nothing will cause an error.");
}
내 HTML 본문
<body onload="checkCookie()">
<form>
Enter Mobile Number: <input type="text" name="mobtel"><br>
<input type="submit" value="Save Cookie" onclick="set_name(this.form)">
</form>
</body>
내 불을 지르고에서 모두 작동하지만 :
Uncaught TypeError: Cannot read property 'value' of undefined
set_name
checkCookie
(anonymous function)
onload
어쩌면 내 코딩 스타일이 잘못되었습니다. 내 코드를 다시 쓸 수 있습니다. 나는 아직도 자바 스크립트에 새로운 사람이다. 당신에게
알려지지 않은 오류 : Uncaught TypeError : 정의되지 않은 'value'속성을 읽을 수 없습니다. 이는 사용자가 아직 전화 번호를 입력하지 않고 브라우저에 쿠키를 저장 한 경우에만 발생합니다. –