动态方法getElementsByTagName()

代码:

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8" />
        <title>getElementsByTagName</title>
        <script type="text/javascript">
            'use strict';
            window.onload = function() {
                let buttonsForTagName = document.getElementsByTagName('button');
                // 0
                alert(buttonsForTagName.length);
                document.body.innerHTML = '<button id="button1">button1</button><button id="button2">button2</button><button id="button3">button3</button>';
                // 3
                alert(buttonsForTagName.length);
            }
        </script>
    </head>

    <body>
    </body>

</html>

备注:

getElementsByTagName()方法一个动态方法。

posted @ 2016-02-27 15:16  Xwoder  阅读(296)  评论(0编辑  收藏  举报