Javascript 如何在两个不同的html上调用localStorage?

Javascript 如何在两个不同的html上调用localStorage?,javascript,html,Javascript,Html,我正在尝试注册并登录html。如果用户在SignUp.html上输入数据,它将另存为localStorage,如果在LogIn.html上输入的数据不等于在SignUp.html中输入的数据,它将不会确认。但不知怎的,函数有点问题。 有人能帮我吗?我对js还是新手 这里是SignUp.html <!DOCTYPE html> <html> <head> <script src = "JS.js"></script> &l

我正在尝试注册并登录html。如果用户在SignUp.html上输入数据,它将另存为localStorage,如果在LogIn.html上输入的数据不等于在SignUp.html中输入的数据,它将不会确认。但不知怎的,函数有点问题。 有人能帮我吗?我对js还是新手

这里是SignUp.html

<!DOCTYPE html>
 <html>
  <head>
   <script src = "JS.js"></script>
  </head>
  <body>
   <form>
    <input id="usernameS"></input>
    <button onclick="confirmInput()" type="button">SignUp</button>
   </form>
  </body>
 </html>

至少修复代码{unsernameS=document.forms[0].usernameL.value;

中的打字错误。您可以使用存储事件在同一来源加载的不同窗口之间进行通信,另请参阅
<!DOCTYPE html>
 <html>
  <head>
   <script src = "JS.js"></script>
  </head>
  <body>
   <form>
    <input id="usernameL"></input>
    <button onclick="LogInput()" type="button">LogIn</button>
   </form>
  </body>
 </html>
var x = "document.getElementById('usernameS')";
    localStorage.setItem("usernameS", x);
    var y = "document.getElementById('usernameL')";
    localStorage.setItem("usernameL", y);

    function confirmInput() {
    alert("Welcome " + usernameS.value + ". You are now registered.");
    window.location.replace('LogIn.html'); }

    function LogInput(x,y) {
    if (x==y)
    {unsernameS = document.forms[0].usernameL.value;
    alert("Welcome " + usernameL.value + "! You just logged in.");}
        else if (x!=y)
        alert("Username not recognized");}