你都没调用checkCookie。。还有本地file调试不要用chrome,本地cookie chrome不存储
  checkCookie()

解决方案 »

  1.   

    搭建一个简单的Web服务器,把html扔里面就可以在浏览器里设置cookies了
      

  2.   

    我在body里调用了,body是这样写的:<body onLoad="checkCookie()">
      

  3.   

    求解决呀~我用360、chrome、ie都试过了,都不能保存cookie,这是为神马呀?
      

  4.   

    360极速模式下就是chrome,ie什么版本的,chrome下没发布的页面不会保存cookie发你代码全来,问个问题东一点西一点,哪知道你哪里出问题
      

  5.   

    好嘛,我全部的代码是这样的:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>表单验证</title>
    <script type="text/javascript">
    var audioElement = document.createElement('audio');  
    audioElement.setAttribute('src', 'song.mp3');
    /*
    function clear()
    {
       Source=document.body.innerHTML;
       document.open();
       document.write("你想看源代码吗?问我要呀~哇咔咔~");
       document.close();
       document.body.innerHTML=Source;

    */
    function PlayAudio()    //播放音频文件
    {  
        audioElement.load;  
        audioElement.play();  
    }
    function checkForm()    //检查内容是否为空
    {
       if(document.test.username.value == "")
       {
         // alert("用户名不能为空!");
         // document.test.username.focus();
     document.getElementById("usernameerr").innerHTML="<font color='red' size='-2'>请输入用户名!" //插入红色的提醒字
         return false;
       }
       PlayAudio();
       document.getElementById("usernameerr").innerHTML="<font color='green' size='-2'>输入正确!"
      // document.getElementById("usernameerr").innerHTML="<img src='1.png' height='20' width='20'>" 
       return true;
    }
    function CheckPSW()    //检查两个元素值是否相等
    {
       if(document.test.password1.value != document.test.password2.value)
       {
          alert("两次输入的密码不一致!");
      document.text.password2.focus();
          return false;
       }
       return true;
    }
    function onlyNum(event)  //输入只能为数字
    {
       //var event = e || window.event;
       if(!((event.keyCode>=48&&event.keyCode<=57))||(event.keyCode>=96&&event.keyCode<=105))
       {
          window.event.keyCode = 0 ; 
          alert("请输入数字!");
      document.test.age.value="";
      document.test.age.focus();
          return false;
       }
       return true;
    }
    function onlyEng(e)    //输入只能为英文
    {
       if(!(e.keyCode >= 65 && e.keyCode<=90))
       {
          alert("请输入英文!");
      document.test.EngName.focus();
      return false;
       }
       return true;
    }
    function checkLength()    //检查输入内容的长度
    {
       if(document.test.phoneNum.value.length != 11)
       {
          alert("手机号码只能是11位!");
      return false;
       }
       //alert("正确的输入!");
       return true;
       alert("正确的输入!");
    }
    function show() 
    {
       myForm = document.test.elements[0].form;
       //以上使用对象的form属性引用文档的表单
       newWin = open("","",height=400,width=400);    //另外打开一个窗口
       newWin.document.write("<h3>表单元素信息:</h3>");
       for(i=0;i<myForm.length;i++)           //循环检测表单元素类型
       {
         if(myForm.elements[i].type=="text")
        myType = "文本框";
     else if(myForm.elements[i].type=="password")
        myType="密码框";
     else if(myForm.elements[i].type=="textarea")
        myType="文本域";
     else if(myForm.elements[i].type=="file")
        myType="文件选择框";
     else if(myForm.elements[i].type=="button")
        myType="按钮";
         else
        myType="其他元素";
         newWin.document.write(myType+"中的值为:"+myForm.elements[i].value+"<p>")
       }
    }function getCookie(c_name)     //检查是否已设置cookie
    {
       if(document.cookie.length>0)
       {
          c_start = document.cookie.indexOf(c_name+"=")  //indexOf()方法可返回某个指定的字符串值在字符串中首次出现的位置。
                                                     //参考:http://blog.163.com/very_apple/blog/static/2775923620109273237597/
      if (c_start != -1)
      {
         c_start=c_start + c_name.length + 1
     c_end=document.cookie.indexOf(";",c_start)
     if(c_end == -1)
     {
        c_end = document.cookie.length
     }
     return unescape(document.cookie.substring(c_start,c_end))//unescape 方法返回一个包含 charstring 内容的字符串值
                                                              //参考:http://chali22.blog.163.com/blog/static/4000369200791525738395/
      }
       }
       return  ""
    }
    function  setCookie(c_name,value,expiredays) //创建一个cookie
    {
        exdate=new Date()
        exdate.setDate(exdate.getDate()+expiredays)
        document.cookie=c_name+"="+escape(value)+((expiredays==null)?";":";expires="+exdate.toGMTString())
     //  var cookieString=c_name+"="+escape(value);
     //判断是否设置过期时间
     /*  if(expireHours>0){
          var date=new Date();
          date.setTime(date.getTime+expireHours*3600*1000);
          cookieString=cookieString+"; expire="+date.toGMTString();
       }
       document.cookie=cookieString;
       */
    }function checkCookie()
    {
       username=getCookie('username')
       if(username != null && username != "")
       {
          alert('欢迎再次回来'+username+'!')
       }
       else
       {
          username=prompt('请输入你的名字:',"")
      if(username != null && username != "")
      {
         setCookie('username',username,365)
      }
       }
    }</script>
    </head>
    <body onLoad="checkCookie()">
    <form name="test" onsubmit="show()">
    用户名:<input type="text" name="username" onblur="checkForm()" >
    <span id="usernameerr"></span>
    <!--<input type="button" onclick="checkForm()" name="check" value="检查">-->
    </br>
    密码:<input type="password" name="password1" onfocus=this.select() ></br>
    确认密码:<input  type="password" name="password2">
    <input type="button" onclick="CheckPSW()" name="check" value="检查">
    </br>
    输入年龄:<input type= "text" onkeypress="onlyNum(event)" name="age" onfocus=this.select()>
    <br/>
    输入手机号码:<input type="text" onkeypress="onlyNum(event)" name="phoneNum" onfocus=this.select()>
    <input type="button" onclick="checkLength()" value="检查"><br/>
    个人简介:<textarea rows=4 onfocus=this.select() onfocus=this.select()></textarea>
    <br/>
    英文名字:<input type="text" onkeypress="onlyEng(event2)" name="EngName" onfocus=this.select()>
    <br/>
    选择文件:<input type=file name=file1 onfocus=this.select()><br/>
    <input type=submit value="提交">
    <input type=reset value="重置">
    <br/>
    </body>
    </html>
      

  6.   

    IE8-,firefox测试没有问题,没发布的网站已经告诉过你不要使用chrome,就是webkit核心的浏览器来查看,不会保存cookie