<html>
<head>
<title>cookie</title>
<script type = "text/javascript">
var user_name;
var del = new Date();
document.write(del.toGMTString());
function check() {
user_name = document.getElementById("user").value;
del.setFullYear(del.getFullYear() + 1);
document.cookie = escape("name") + "=" + escape(user_name) + ";expires = "+ del.toGMTString();
alert(document.cookie);
}
</script>
</head>
<body>
<form>
username : <input type = "text" id = "user"></input>
<input type = "button" value = "enter" onClick = "check()"></input>
</form>
</body>
</html>
在Chrome中Cookie不想弹出警报,但是在Firefox中可以工作,但只显示用户的名称。有人有什么建议吗?
document.write
是用来做什么的?如果将其删除会发生什么?此外,您是否在浏览器控制台中看到任何 JS 错误? - Spudley