为了账号安全,请及时绑定邮箱和手机立即绑定

点击标题为什么显示的是文字?

<!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("sex");
                                                     alert(myS.length);
                                                               }
             
             function getTagElements()          
             {              var myI = document.getElementsByTagName("input");              
             alert(myI.length);          
             }              
             </script>           
             </body>
             </html>


正在回答

2 回答

getElementById() 方法可返回对拥有指定 ID 的第一个对象的引用。

H1标签上 有onclick 所以是可以点击。点击之后调用getValue()函数,而这个函数中有:alert(myH.innerHTML);

而这个作用是:innerHTML 属性设置或返回表格行的开始和结束标签之间的 HTML。

0 回复 有任何疑惑可以回复我~
#1

岁月忽已晚_7 提问者

非常感谢!
2018-08-09 回复 有任何疑惑可以回复我~

你这上面有好多都没遵循大小写

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

点击标题为什么显示的是文字?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信