<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>元素节点</title>
</head>
<body>
<form>
<table align="center" width="500px" height="50%" border="1">
<tr>
<td align="center" width="100px">学号:</td>
<td align="center" width="300px">
<input type="text" name="">
</td>
</tr>
<tr>
<td align="center" width="100px">姓名:</td>
<td align="center" width="300px">
<input type="text" name="name"></td>>
</tr>
<tr>
<td align="center" width="100px">性别:</td>
<td align="center" width="300px">
<input type="radio" name="sex" value="男">男
<input type="radio" name="sex" value="女">女</td>
</tr>
<tr>
<td align="center" width="100px">年龄:</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="address"></td>
</tr>
</table>
</form>
<h1 id="myHead" onclick="getHead()">看看三种获取节点的方法</h1>
<p>点击标题弹出它的值</p>
<input type="button" onclick="getTagElements()" value="看看标签名称为input的有几个?">
<input type="button" onclick="getElements()" value="看看节点名称为sex的有几个?" >
<script type="text/javascript">
function getValue()
{
var myH=document.getElementsById("myHead");
alert(myH.innerHTML);
}
function getElements() {
var myS=document.getElementsByName("sex");
alert(myS.length);
}
function getTagElements(){
var myI=document.getElementsByTagName("input");
alert(myI.length);
//alert("documet.getElementsByTagName("input").length");
}
</script>
</body>
</html>
onclick="getHead()"
function getValue()
方法名要一致
刚试过了,并没有报错误,不会用,我用的sublime,控制台刚去百度了,还是不太清楚,求指教