下面代码将创建一个cookie,该cookie名称为UserName,值为Paul,过期时间为7天后(2015年6月29日)
<span style="font-size:24px;"><!DOCTYPE html>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title></title>
<script type ="text/javascript">
var date=new Date();
date.setDate((date.getDate()+7));
document.cookie ='UserName='+'Paul'+';expires='+ date;
alert(document.cookie);
</script>
</head>
<body>
<p>创建一个cookie</p>
</body>
</html></span>
原文地址:http://blog.csdn.net/xfz0330/article/details/46622729