未捕获引用错误:赋值中的左侧无效(更改css背景色)



这是一个注册页面。我试着写一些关于表单验证的东西。

我想得到"em1",并在输入密码>0时将其颜色更改为高亮,以向注册人员显示他/她的密码太弱。

但我不知道为什么会发生错误,这是我的代码:

var em1 = document.getElementById("em1");
var em2 = document.getElementById("em2");
var em3 = document.getElementById("em3");
pass_input.onkeyup = function() {
  if (this.value.length > 0) {
    em1.style.background - color = "yellow";
  }
}
#pass_em {
  opacity: 0.5;
  display: inline-block;
  width: 150px;
  text-align: center;
  background-color: #ccc;
}
#em1 {
  width: 45px;
  text-align: center;
  display: inline-block;
}
#em2 {
  width: 45px;
  text-align: center;
  display: inline-block;
}
#em3 {
  width: 45px;
  text-align: center;
  display: inline-block;
}
<tr>
  <td class="tag">password:</td>
  <td>
    <input type="password" id="password" name="password" />
    <div id="pass_em">
      <em id="em1">weak</em>
      <em id="em2">soso</em>
      <em id="em3">okey</em>
    </div>
    <span id="password_tip" style="color:red;">*</span>
  </td>
</tr>

我想这是由于我的方法改变了"em1"的"背景色",是吗?

你不能这样做:

em1.style.background - color = "yellow";

这是正确的语法:

em1.style.backgroundColor = "yellow";

最新更新