zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然 JAVASCRIPT开发学习:HTML DOM 集合(Collection)

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <h2>JavaScript HTML DOM</h2>
    
    <p>Hello World!</p>
    
    <p>Hello Runoob!</p>
    
    <p id="demo"></p>
    
    <script>
    var myCollection = document.getElementsByTagName("p");
    document.getElementById("demo").innerHTML = "第二个段落的内容为:<span style='color:red;'> " + myCollection[1].innerHTML + '</span>';
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <h2>JavaScript HTML DOM</h2>
    
    <p>Hello World!</p>
    
    <p>Hello Runoob!</p>
    
    <p id="demo"></p>
    
    <script>
    var myCollection = document.getElementsByTagName("p");
    document.getElementById("demo").innerHTML = "文档包含" + myCollection.length + " 个段落。";
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <h2>JavaScript HTML DOM</h2>
    
    <p>Hello World!</p>
    
    <p>Hello Runoob!</p>
    
    <p>点击按钮修改 p 元素的背景颜色。</p>
    
    <button onclick="myFunction()">点我</button>
    
    <script>
    function myFunction() {
        var myCollection = document.getElementsByTagName("p");
        var i;
        for (i = 0; i < myCollection.length; i++) {
            myCollection[i].style.color = "red";
        }
    }
    </script>
    
    </body>
    </html>

  • 相关阅读:
    腾讯// 反转字符串
    腾讯//Multiply Strings 字符串相乘
    腾讯//盛最多水的容器
    腾讯//删除排序数组中的重复项
    腾讯//删除排序数组中的重复项
    C语言中的预处理命令
    Python十大应用领域与就业方向
    Python的主要应用领域及应用场景
    Git命令_git status
    Git命令_git add快速添加文件到暂存区
  • 原文地址:https://www.cnblogs.com/tszr/p/10944353.html
Copyright © 2011-2022 走看看