var oObject = document.all.item("sample");
if (oObject != null){
if (oObject.length != null){
for (i = 0; i < oObject.length; i++){
alert(oObject(i).tagName);
}
}
}
else{
alert(oObject.tagName);
}
if (oObject != null){
if (oObject.length != null){
for (i = 0; i < oObject.length; i++){
alert(oObject(i).tagName);
}
}
}
else{
alert(oObject.tagName);
}
for(i = 0; i < document.all.length; i++){
alert(document.all(i).tagName);
}
<head>
<script>
function countTags(n){
var numtags=0;
if(n.nodeType==1)numtags++;
var children=n.childNodes;
for(var i=0;i<children.length;i++){
numtags+=countTags(children[i])};
return numtags;
}
</script>
</head>
<body onload="alert('这个文档含有'+countTags(document)+'个标记')">
this is a<i> sample</i>
<body>
window.onload = takeTag;
function takeTag()
{
for(i = 0; i < document.all.length; i++){
alert(document.all(i).name);
}
}
</script>