显示HTML文件的所有元素
<html>
<head>
<title>获取HTML文件的元素</title>
<script language="JavaScript">
function showElements(){
var strTags = "";
for(var i=0; i<document.all.length; i++){
objEle = document.all(i);
strTags += objEle.tagName + " " + objEle.sourceIndex + " ";
}
alert(strTags);
}
function showBodyElements(){
var strTags = "";
for(var i=0; i<myBody.all.length; i++){
strTags += myBody.all[i].tagName + " ";
}
alert(strTags);
}
function showElement(index){
alert(document.all(index).tagName);
}
</script>
</head>
<body id="myBody">
<h2>显示HTML文件的元素</h2>
<hr>
<p>获取<b>HTML</b>文件的元素</p>
<form>
<input type="button" onclick="showElements()" value="文件的元素">
<input type="button" onclick="showBodyElements()" value="Body区域的元素">
<input type="button" onclick="showElement(4)" value="第五元素">
</form>
</body>
</html>