我收到此错误:语法错误:输入意外结束;我的 cookie 创建代码有什么问题



我目前正在尝试创建一个cookie存储和制作程序。我从互联网上获得了这个基本代码,但我目前正在尝试根据自己的喜好进行调整。我以为我的代码是完整的,但是当我运行它时,我收到此错误。这是代码:

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <form name="myform" action="">
         Enter name: <input type="text" name="customer" value= "hello"/>
         <button type="name" onclick= "WriteCookie()">Login</button>
      </form>
       <form name="myform" action="">
         <p> click the following button and see the result:</p>
         <button type="GetCookies" onclick= "ReadCookie()">Get Cookies</button>
      </form>
   <script>
      function WriteCookie()
      {
        cookievalue= "hello";
        document.cookie = cookievalue;
        document.write ("Setting Cookies : " + "name=" + cookievalue );
      }
      function ReadCookie()
            {
               var allcookies = document.cookie;
               document.write ("All Cookies : " + allcookies );
               
               // Get all the cookies pairs in an array
               cookiearray = allcookies.split(';');
               
               // Now take key value pair out of this array
               /*for(var i=0; i<cookiearray.length; i++){
                  name = cookiearray[i].split('=')[0];
                  value = cookiearray[i].split('=')[1];
                  document.write ("Key is : " + name + " and Value is : " + value);
               }
            } */
    </script>
  </body>
</html>

我是HTML5编程的初学者,没有Javascript的先验知识(没有用),我只有12(不是找借口),所以请尝试以最简单的方式解释它,谢谢。

你的一条评论在错误的行上结束了:

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <form name="myform" action="">
         Enter name: <input type="text" name="customer" value= "hello"/>
         <button type="name" onclick= "WriteCookie()">Login</button>
      </form>
       <form name="myform" action="">
         <p> click the following button and see the result:</p>
         <button type="GetCookies" onclick= "ReadCookie()">Get Cookies</button>
      </form>
   <script>
      function WriteCookie()
      {
        cookievalue= "hello";
        document.cookie = cookievalue;
        document.write ("Setting Cookies : " + "name=" + cookievalue );
      }
      function ReadCookie()
            {
               var allcookies = document.cookie;
               document.write ("All Cookies : " + allcookies );
               
               // Get all the cookies pairs in an array
               cookiearray = allcookies.split(';');
               
               // Now take key value pair out of this array
               /*for(var i=0; i<cookiearray.length; i++){
                  name = cookiearray[i].split('=')[0];
                  value = cookiearray[i].split('=')[1];
                  document.write ("Key is : " + name + " and Value is : " + value);
               } */
            }
    </script>
  </body>
</html>

最新更新