Cookie不会通过javascript命令执行提示和警报

时间:2016-11-18 04:44:59

标签: javascript html cookies alert

我一直在尝试制作登录页面。它检查是否已存在用户名的cookie,如果是,则要求提供登录详细信息。否则它通过注册程序。但是,这不起作用。它只是使代码出现在控制台上。我的完整代码位于链接https://github.com/TheNumnut/Wars-of-Shares/blob/master/Login/index.html上的github上 我认为我的代码的一部分不起作用是:

function checkCookie(checkusername, checkpassword, register) {
  if (getCookie("username") != "") {
    setCookie("username", checkusername, 365);
    setCookie("password", checkpassword, 365);
  }
  else {
    if (checkusername != getCookie("username") {
      alert("Username wrong");
      window.close();
    }
    else {
      if (checkpassword != getCookie("password") {
        alert("Password wrong");
        window.close();
    window.open("https://thenumnut.github.io/Wars-of-Shares/", "_self");
}

</script> 
</head> 
<body>
var username = prompt("Username: ");
var password = prompt("Password: ");
checkCookie(username, password);

请告诉我是否有任何问题。打印到网站的部分来自var username = prompt(“Username:”);直到checkCookie(用户名,密码);. 任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

您的提醒未显示,因为您在html中调用了&#34; checkCookie(用户名,密码);&#34; 功能,而不是在javascript中。并且还缺少一些括号。

g++ main.cpp GradeBook.cpp -o example.out
             ~~~~~~~~~~~~~

答案 1 :(得分:0)

你在以下几行中遗漏了额外的内容

if (checkusername != getCookie("username") {

if (checkpassword != getCookie("password") {