猿问

获取body 所有的子元素,这样写为什么不行?

<script type="text/javascript">

        countBodyChildren() {

            var body_element = document.getElementsByTagName("body")[0];

            alert(body_element.childNodes.length);

        }

        window.onload = countBodyChildren;

    </script>


千巷猫影
浏览 976回答 1
1回答

DIEA

函数声明语句写错了,哪能这么搞var countBodyChildren = function() {&nbsp; &nbsp; var body_element = document.getElementsByTagName("body")[0];&nbsp; &nbsp; &nbsp;alert(body_element.childNodes.length); };
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答