获取节点的几种小案例
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
window.onload=function(){
var bjNode = document.getElementById("bj")
alert(bjNode);
var liNode = document.getElementsByTagName("li");
alert(liNode.length);
var cityNode = document.getElementById("city");
var cityLiNode = document.getElementsByTagName("li");
alert(cityLiNode.length)
var genderNode = document.getElementsByName("gender");
alert(genderNode.length);
var bjjNode = document.getElementsByName("beijing");
alert(bjjNode.length);
}
</script>
</head>
<body>
<p>你会选择哪个城市?</p>
<ul id="city">
<li id="bj" name="beijing">北京</li>
<li>上海</li>
</ul>
<br></br>
<p>游戏?</p>
<ul id="game">
<li id="rl">斗地主</li>
<li>麻将</li>
<br><br>
sex:
<input type="radio" name="gender" value="man"/>Man
<input type="radio" name="gender" value="women"/>Women
</body>
</html>