HTML,CSS,JS脚本错误。错误解释堆栈

时间:2017-09-10 20:24:17

标签: javascript html css firebase

我正在使用firebase处理待办事项列表应用程序,但是我收到错误Script error. Error Interpreting Stack。它没有明显的意义,所以我不知道该怎么想。

我也试过评论我的所有JS,但我仍然得到了相同的结果。我听说它可能是一个外部链接,但添加crossorigin=anonymous并没有帮助。

以前所有代码都适用于我,所以错误对我来说是新的。



var config = {
  apiKey: "AIzaSyBIV0dPpIwuZadvGfmkIPF7gsykIvt8n4M",
  authDomain: "to-do-332c9.firebaseapp.com",
  databaseURL: "https://to-do-332c9.firebaseio.com",
  projectId: "to-do-332c9",
  storageBucket: "to-do-332c9.appspot.com",
  messagingSenderId: "281739919235"
};
firebase.initializeApp(config);

const txtEmail = document.getElementById('txtEmail');
const txtPassword = document.getElementById('txtPassword');
const btnLogin = document.getElementById('btnLogin');
const btnSignup = document.getElementById('btnSignup');
const btnLogout = document.getElementById('btnLogout');

var ref = firebase.database().ref('');

btnLogin.addEventListener('click', e => {  
  document.getElementById('form').classList.add('hide');    

  const email = txtEmail.value;
  const pass = txtPassword.value;
  const auth = firebase.auth();

  const promise = auth.signInWithEmailAndPassword(email, pass);
  promise.catch(e => console.log(e.message));
  
  ref = firebase.database().ref('');
});

btnSignup.addEventListener('click', e => {
  const email = txtEmail.value;
  const pass = txtPassword.value;
  const auth = firebase.auth();

  const promise = auth.createUserWithEmailAndPassword(email, pass);
  promise.catch(e => console.log(e.message));

});

firebase.auth().onAuthStateChanged(firebaseUser => {
  if (firebaseUser) {
    btnLogout.classList.remove('hide');
    document.getElementById('form').classList.add('hide');    
  } else {
    btnLogout.classList.add('hide');
    document.getElementById('messagesTitle').classList.add('hide');
  }
});

.container {
  width: 70%;
  height: 100%;
  background: #87b5ff;
  margin: 10% auto;
  color: #fff;
  padding: 20px;
  border-radius: 10px;
  max-width: 400px;
}

#signin {
  margin: auto;
  padding-top: 10px;
}

.hide {
  display:none;
}

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>To-Do</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <div id="form" class="container">
      <h3>Login</h3>
      <form id="signin">
        <input type="email" class="form-control" id="txtEmail" placeholder="Email">
        <input type="password" class="form-control mb-3" id="txtPassword" placeholder="Password">
      </form>
      <button id="btnLogin" class="btn btn-primary">Login</button>
      <button id="btnSignup" class="btn btn-success">Sign up</button>
      <button id="btnLogout" class="btn btn-info hide">Logout</button>
    </div>
    
    <script src="https://www.gstatic.com/firebasejs/4.3.1/firebase.js"></script>
    <script src="main.js"></script>
  </body>
</html>
&#13;
&#13;
&#13;

0 个答案:

没有答案