Javascript - 使用Cookie [重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我正在学习使用Javascript创建cookie并在页面中创建了这个实验性日志。它100%工作,但我希望能够显示用户的用户名和密码。这可以用Javascript中的cookie完成吗?我在下面附上了我目前的代码:

function displayCookies(){
    if (GetCookie("user") || GetCookie("pass")){
        document.regform.usercookie.value = GetCookie("user");
        document.regform.passcookie.value = GetCookie("pass");
    }else{
        document.cregistrationform.usercookie.value = "Make sure you have signed up!";
        document.registrationform.passcookie.value = "Make sure you have signed up!";
    }
}
function createCookies(){
    var username = document.registrationform.user.value;
    var password = document.registrationform.pass.value;
    var date = Date();
    SetCookie("user", user);
    SetCookie("pass", pass);
    alert("You have registered!");
    alert("Welcome back" + username ". Your last visit was" + date);
}

function reloadPage() {
  location.reload(); 
}

</script>
javascript cookies
1个回答
0
投票

第一个功能在注册表格前面包含“c”?那应该删除:

function displayCookies(){
    if (GetCookie("username") || GetCookie("password")){
        document.registrationform.usernamecookie.value = GetCookie("username");
        document.registrationform.passwordcookie.value = GetCookie("password");
    }else{
        document.registrationform.usernamecookie.value = "Please register!";
        document.registrationform.passwordcookie.value = "Please register!";
    }
}

重复的问题:How do I create and read a value from cookie?

© www.soinside.com 2019 - 2024. All rights reserved.