<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cookie的应用</title>
<script type="text/javascript">
//cookie的通用函数function setcookie(name,value,expires,path,domain,secure){
alert(1);
var normalcookie=name+'='+encodeURI(value)
+((expires)? ';expires='+expires.toGMTString() : '')
+((path)? ';path='+path : '')
+((domain)? ';domain='+domain : '')
+((secure)? ';secure='+secure : ''); 

//因为name为必选属性,所以不要判断是否存在

document.cookie=normalcookie;
}

function curcookie(){
var text2=document.form1.text2.value;
var password2=document.form1.password2.value;
var now=new Date();
now.setDate(getDate()+365);   //设置有效期为一年
setcookie('text2',text2,now);
setcookie('password2',password2,now);
document.write(document.cookie);
}</script><style type="text/css"></style>
</head>
 
<body>
<form name="form1" method="post" onsubmit="runcookie()">
            
Cookie的通用函数:<br /><br />
用户名:<input type="text" name="text2" />
密码:<input type="password" name="password2" />
<input type="button" name="button1" value="提交" onclick="curcookie()" />
<input type="reset" name="reset1" value="重置" />
</form>
</body>
</html>

解决方案 »

  1.   

    function curcookie(){
    var text2=document.form1.text2.value;
    var password2=document.form1.password2.value;
    var now=new Date();
    now.setDate(now.getDate()+365); //设置有效期为一年
    setcookie('text2',text2,now);
    setcookie('password2',password2,now);
    document.write(document.cookie);
    }
      

  2.   

    是呀1楼真历害这也看出来了, getDate()怎么出来的都不知道, 历害呀 顶下。