问答详情
源自:9-3 getElementsByTagName()方法

看看三种获取节点的方法

这里个编程里的三种方法中的第一种方法指的是哪个?我写的是吗?

提问者:ChrisKyle 2017-03-13 22:55

个回答

  • 慕移动9181930
    2022-03-23 21:18:04

    试了,还是不行,提示如故。

  • qq_忧蓝天空_0
    2017-05-10 18:00:34

    第一种方法是获取名为:myHead的ID

  • 吱吱叫的老鼠
    2017-03-14 11:02:27

    <!DOCTYPE HTML>
    <html>  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
    <title>JavaScript</title>  
    </head>  
    <body>  
        
            <form name="Input">
                <table align="center" width="500px" height="50%" border="1">
                    <tr>
                        <td align="center" width="100px">
                            学号:
                        </td>
                        <td align="center" width="300px">
                            <input type="text" id=userid name="user" onblur="validate();">
                            <div id=usermsg></div>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100px">
                            姓名:
                        </td>
                            <td align="center">
                            <input type="text" name="name">
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="%45">
                            性别:
                        </td>
                        <td align="center">
                            <input type="radio" name="sex" value="男">
                            男
                            <input type="radio" name="sex" value="女">
                            女
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="30%">
                            年龄:
                        </td>
                        <td align="center" width="300px">
                            <input type="text" name="age">
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100px">
                            地址:
                        </td>
                        <td align="center" width="300px">
                            <input type="text" name="addr">
                        </td>
                    </tr>

                </table>
            </form>
            <h1 id="myHead" onclick="getValue()">
                看看三种获取节点的方法?
            </h1>
            <p>
                点击标题弹出它的值。
            </p>
            <input type="button" onclick="getElements()"
                value="看看name为sex的节点有几个?" />
            <Br>
            <input type="button" onclick="getTagElements()"
                value="看看标签名为input的节点有几个?" />
                
         <script type="text/javascript">
             function getValue()
              {
                 var myH = document.getElementById("myHead");
                  alert(myH.innerHTML);
              }
              function getElements()
              {
                 var myS = document.getElementsByName("radio");
                  alert(myS.length);
              }

              function getTagElements()
              {
                var myI = document.getElementsByTagName("input");   
                  alert(myI.length);
              }
             
         </script>        

        </body>
    </html>

  • 吱吱叫的老鼠
    2017-03-14 11:01:48

    我这样理解的:第一个 document.getElementById; 第二个 document.getElementsByName; 第三个 document.getElementsByTagName;