Home  >  Q&A  >  body text

关于js代码运行顺序问题

583ebaab0001404205000334.jpg

上图中如果把 <script> 放在 <ul> 的上面,是不是就得不到 list 的长度了。

document,getElementByTagName("li") 这个应该算是声明了要调用下面代码了吧。


phpcn_u224phpcn_u2242766 days ago921

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-09-30 22:57:35

    About the issue of the running order of js code-PHP Chinese website Q&A-About the issue of js code running order-PHP Chinese website Q&A

    Take a look around and learn.

    reply
    0
  • 阿神

    阿神2016-12-19 14:12:43

    把<script>放在<ul>上面是得不到list的长度的,因为DOM操作必须等待html文档加载完毕才可以操作,如果把<script>放在前面的话,先执行的是<script>代码,然后按照顺序再执行html里的东西,所以得不到list的长度。

    reply
    1
  • Cancelreply