zoukankan      html  css  js  c++  java
  • JavaScript续

    DOM:一种方便处理层次型文档的一种技术。

    获取HTML元素: 

    1、getElementById 方法:

      根据HTML元素的ID属性来得到HTML元素。在HTML文档中,id属性值是唯一的。  

      <body>
    <!-- 用于输入消息文本框 -->
    <input type = "text" id ="name"/>
    </body>

    2、getElementsByTagName方法 :

      可以根据HTML的标签类型来获得一个相同的HTML元素的数组。 

    3、getElementsByName 方法: 

      通过HTML元素的name属性获得相应的HTML元素集合。由于HTML元素的name属于并不唯一,因此,使用getElementsByName方法有可能得到多个

    相同的name属性值的HTML元素。如:

    <html>
    <head>
    <title>getElementHtml</title>
    <script type = "text/javaScript">
    function volution()
    {
    //获得一个文本框对象数组
           var oTexts = document.getElementsByName("tests") ;
    if (oTexts.length == 0 )
    {
    alert(
    "Error!");
    return ;
    }
    alert(oTexts.length) ;
    for (var i = 0 ; i < oTexts.length ; ++ i)
    oTexts[i].value
    = i ;
    }
    </script>
    </head>
    <body>
    <!-- 5个文本框 -->
    <input type = "text" name = "tests" /> <p/>
    <input type = "text" name = "tests" /> <p/>
    <input type = "text" name = "tests" /> <p/>
    <input type = "text" name = "tests" /> <p/>
    <input type = "text" name = "tests" /> <p/>
    <input type = "button" value = "getElementByName" onclick = "volution()" />
    </body>
    </html>
  • 相关阅读:
    树的直径
    Codeforces 734E Anton and Tree(缩点+树的直径)
    Codeforces 948D Perfect Security(字典树)
    Codeforces 954D Fight Against Traffic(BFS 最短路)
    Codeforces 954C Matrix Walk (思维)
    Codeforces 950D A Leapfrog in the Array (思维)
    Codeforces 946D
    Invitation Cards POJ-1511 (spfa)
    spfa 单源最短路究极算法
    Currency Exchange POJ
  • 原文地址:https://www.cnblogs.com/jbelial/p/2380843.html
Copyright © 2011-2022 走看看