【问题标题】:display few elements only for a particular user, not able to do it properly仅针对特定用户显示少量元素,无法正确执行
【发布时间】:2021-04-02 05:29:29
【问题描述】:

它显示错误,说明无法读取属性“样式”。 我以类似的方式看到了许多代码。我找不到错误。

function login()
{
 
  var email = document.getElementById("email_field").value;
  var password = document.getElementById("password_field").value;
  firebase.auth().signInWithEmailAndPassword(email, password)
  .then(user => {
    
    console.log(user);
  
    alert("Welcome " +email);
    
    window.location.href = "Home.html";
    if (email = "***@gmail.com"){
      document.getElementById("gameurl").style.display="block";
      document.getElementById("gameimg").style.display="block";
      document.getElementById("gamename").style.display="block";
    }else{
      document.getElementById("gameurl").style.display="none";
      document.getElementById("gameimg").style.display="none";
      document.getElementById("gamename").style.display="none";
    }
 
  }).catch(function(error) {
    
    var errorCode = error.code;
    var errorMessage = error.message;

    window.alert("Error : " + errorMessage);
 });
}

【问题讨论】:

  • 看来您可能有多个错误。我试图在下面指出一个。我认为如果您需要完整的帮助来解决您的问题,您将不得不粘贴您的 HTML。

标签: javascript firebase google-cloud-firestore firebase-authentication


【解决方案1】:

您的if 声明不正确。您需要使用=====,但一个等号表示您设置变量,而不是比较它。

【讨论】:

  • 我认为这不是问题,即使我更改它,它也会显示一个额外的错误电子邮件未定义无法读取 null 的属性样式
  • 这绝对是个问题,你看我上面的评论了吗?您在页面上有两个或更多问题。如果您想修复上面描述的那个,那么您需要在此处发布您的 HTML。否则,没有人能帮你解决这个问题——信息不够。
  • 我应该分享哪个 html 页面?登录页面或主页html?登录后,对于特定用户,我想显示一些东西。请帮助我解决问题。
  • 您的 javascript 存在严重问题。更改位置后,您不能转到另一个名为 Home.html 的页面并添加 if-else 语句。您必须将 if-else 子句添加到 Home.html 的顶部。您不能在一个页面上运行影响不同页面上 DOM ID 的 javascript。 Javascript 仅适用于当前页面。
猜你喜欢
  • 1970-01-01
  • 2017-07-25
  • 1970-01-01
  • 2021-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多