Я получил эту ошибку: SyntaxError: Неожиданный конец ввода;Что не так с моим кодом создания файлов cookie? - PullRequest
0 голосов
/ 25 января 2019

Я сейчас пытаюсь создать программу для хранения и создания файлов 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 (не оправдываться), поэтому, пожалуйста, попробуйте объяснить это как можно проще, спасибо.

1 Ответ

0 голосов
/ 25 января 2019

Конец одного из ваших комментариев в неправильной строке:

<!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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...