繁体   English   中英

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

[英]I got this error: SyntaxError: Unexpected end of input; What is wrong with my cookie creating code?

我目前正在尝试创建一个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编程的初学者,以前没有Java知识(没有用)。我只有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> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM