【问题标题】:javascript Cannot read property 'children' of null whiltejavascript无法读取null whilte的属性'children'
【发布时间】:2018-04-02 12:12:26
【问题描述】:

我在codepen 有这个 sn-p 代码,它运行良好,但是 尝试将其复制到我的网站时显示此错误:

(index):257 Uncaught TypeError: Cannot read property 'children' of null
    at (index):257
(anonymous) @ (index):257

这意味着我网站中的这一行:

var count = items.children.length;

我只是复制编译后的html、css和js,没有任何编辑,我可以知道为什么会这样吗?

【问题讨论】:

  • items 返回什么? :)
  • @dan,我的意思是在你的网站上......不是在代码笔上。
  • 错误提示items 是null。您的问题中没有任何信息可以告诉我们为什么您认为 items 不应该是 null。
  • 你把脚本粘贴到底部了吗

标签: javascript html css haml


【解决方案1】:

您的 <head></head> 标记中可能包含 Javascript 代码。

DOM 还没有准备好。



尝试在 </body> 标记之前复制您的 <script>code</script>。

【讨论】:

  • 还是同样的问题
  • 你按STRG + SHIFT + R了吗?因为它可能在缓存中。
  • 你是天才。谢谢
猜你喜欢
  • 2021-10-31
  • 1970-01-01
  • 2013-03-21
  • 2019-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-17
相关资源
最近更新 更多