作业3.html?_ijt=5h8h0o4smtc0onigbr9fumlgfd:24 Uncaught TypeError: Cannot read property ‘style’ of undefined
at HTMLLIElement.lis..onclick (作业3.html?_ijt=5h8h0o4smtc0onigbr9fumlgfd:24)
lis..onclick @ 作业3.html?_ijt=5h8h0o4smtc0onigbr9fumlgfd:24
报错信息('style' of undefined at HTMLLIElement.lis)
这是代码,报错信息在lis[i].style.backgroundColor=“red”;
报错意思:style没有值

改正方法:
报错信息('style' of undefined at HTMLLIElement.lis)
lis[i]改为this即可代替事件绑定
法二:经过讨论,把var变量换成let
命名变量时,采用let,在es6语法中,let所在代码块会形成一个封闭空间[作用域],不会受到外部赋值的影响
在for循环中,循环条件[语句]会形成一个父作用域,循环体内部则是一个子作用域

相关文章:

  • 2022-12-23
  • 2021-12-13
  • 2021-05-19
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
猜你喜欢
  • 2021-09-04
  • 2021-09-29
  • 2021-09-02
  • 2021-10-11
  • 2022-12-23
  • 2021-08-31
  • 2021-04-24
相关资源
相似解决方案