美文网首页
document.getElementsByTagName()/

document.getElementsByTagName()/

作者: Jadon7 | 来源:发表于2018-10-06 22:41 被阅读0次
    <!DOCTYPE html>
    <html>
    <head>
        <title>get Elements By Tag Name</title>
    </head>
    <script type="text/javascript">
        window.onload=function()
        {
            var aDiv=document.getElementsByTagName('div');
            for (var i = 0; i<aDiv.length; i++)
            {
                aDiv[i].style.background='red';
            };
        };
    </script>
    <style type="text/css">
        div{
            width: 100px;
            height:100px;
            border: 1px solid red;
            margin: 50px;
            float: left;
        }
    </style>
    <body>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:document.getElementsByTagName()/

          本文链接:https://www.haomeiwen.com/subject/qkehaftx.html