日期:2014-05-17 浏览次数:20722 次
<html>
<body>
<p id="p1">p1</p>
<div id="mar">
<div>
<div>2</div>
<div>3</div>
</div>
</div>
<script type="text/javascript">
var divs = document.getElementsByTagName("div");
var index = 0;
for (var x in divs)
{
index++;
var p = divs[x];
if (typeof(p) != "object" ) {continue;};
alert(index + ":" + typeof(divs[x]) + "::" + divs[x] + ":::" + divs[x].innerHTML)
};
</script>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<p id="p1">p1</p>
<div id="mar"><div><div>2</div><div>3</div></div></div>
<script type="text/javascript">
var divs = document.getElementsByTagName("div");
var index = 0;
/*
for (var x in divs)
{
index++;
var p = x;
///if (typeof(p) != "object" ) {continue;};
alert(index + ":" + p.innerHTML);
}*/
for(var i=0;i<divs.length;i++){
index++;
var p = divs.item(i);
alert(index + ":" + p.innerHTML);
}
</script>
</body>
</html>