大家好,我正在尝试创建 cookie,但没有成功。这是我的站点代码,我不知道为什么我无法获取我创建的 cookie?
添加了编辑站点的完整代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>yensdesign.com - How to create a stuning and smooth popup in jQuery</title>
<link rel="stylesheet" href="general.css" type="text/css" media="screen" />
<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js" type="text/javascript"></script>
<script src="popup.js" type="text/javascript"></script>
<script type="text/javascript">
function setCookie(name,value,days)
{
var date=new Date();
var exdays = days*24*60*60*1000;
date.setDate(date.getDate() + exdays);
var c_value=escape(value) + ((days==null) ? "" : "; expires="+date.toUTCString());
document.cookie=name + "=" + c_value;
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function deleteCookie(name) {
setCookie(name,"",-1);
}
</script>
</head>
<body onload="setCookie('myCookie', 'myValue', 1);">
<center>
<a href="http://www.yensdesign.com"><img src="logo.jpg" alt="Go to yensdesign.com"/></a>
<div id="button"><input type="submit" value="Press me please!" /></div>
<div id="button"><input type="submit" value="Cookie!" onclick=getCookie('myCookie'); /></div>
</center>
<div id="popupContact"></div>
<div id="backgroundPopup"></div>
</body>
</html>
以及似乎不起作用的cookie创建:
<body onload="setCookie('myCookie', 'myValue', 1);">
那么这里的问题是什么?