javascript - The JS code is compiled successfully, but an error is reported on the console. What is the problem?
大家讲道理
大家讲道理 2017-07-05 10:58:11
0
5
828
  • red
  • 1
  • 1
  • 1
  • red
  • 1
  • 1
  • 1


# The color of li has changed, but why does the console still report an error?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all (5)
typecho

ulArry is a NodeList object. For in not only obtains two Dom nodes, but also length, item(), namedItem(). So when it reaches length, an error is reported.
You can print out ulArry[i] in the loop and see

    迷茫

    You can see why the error is reported by looking at the picture, but as for why there is a length in in, this i is worth waiting for the expert to answer

      迷茫

      Put the code into $(function(){}) and try it

        扔个三星炸死你

        for in will report an error but for will not. The second ul class is not just one, but two. It is recommended to getElementsByTagName

          我想大声告诉你

          Please make sure the document is loaded before proceeding

            Latest Downloads
            More>
            Web Effects
            Website Source Code
            Website Materials
            Front End Template
            About us Disclaimer Sitemap
            php.cn:Public welfare online PHP training,Help PHP learners grow quickly!