Cookies 不会通过 javascript 命令执行提示和警报
Cookies will not execute a prompt and alert through a javascript command
我一直在尝试做一个登录页面。它检查用户名是否已经有 cookie,如果有,它会询问登录详细信息。否则通过注册程序。但是,这不起作用。它只是让代码出现在控制台上。我的完整代码在 link 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(用户名,密码);。
任何帮助将不胜感激。
您的提醒未显示,因为您在 html 而不是 javascript 中调用了 "checkCookie(username, password);" 函数。还有一些括号丢失了。
<script>
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");
}
}
}
}
checkCookie(username, password);
</script>
您在以下行中缺少一个额外的 )
if (checkusername != getCookie("username") {
和
if (checkpassword != getCookie("password") {
我一直在尝试做一个登录页面。它检查用户名是否已经有 cookie,如果有,它会询问登录详细信息。否则通过注册程序。但是,这不起作用。它只是让代码出现在控制台上。我的完整代码在 link 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(用户名,密码);。 任何帮助将不胜感激。
您的提醒未显示,因为您在 html 而不是 javascript 中调用了 "checkCookie(username, password);" 函数。还有一些括号丢失了。
<script>
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");
}
}
}
}
checkCookie(username, password);
</script>
您在以下行中缺少一个额外的 )
if (checkusername != getCookie("username") {
和
if (checkpassword != getCookie("password") {