理解document.all[]
从IE4开始IE的object model才增加了 document.all[],来看看 document.all[]的Description:
Array of all HTML tags in the document.Collection of all elements contained by the object.
从IE4开始IE的object model才增加了 document.all[],来看看 document.all[]的Description:
Array of all HTML tags in the document.Collection of all elements contained by the object.
也就是说
document.all[]是文档中所有标签组成的一个数组变量,包括了文档对象中所有元素(见例1)。
IE’s document.all collection exposes all document elements.This array provides access to every element in the document.
IE’s document.all collection exposes all document elements.This array provides access to every element in the document.
document.all[]这个数组可以访问文档中所有元素。
当然也可以这样用:
<input type="button" value="Align Left"
οnclick=" document.all['heading1'].align='left';" />
<input type="button" value="Align Center"
οnclick=" document.all['heading1'].align='center';" />
<input type="button" value="Align Right"
οnclick=" document.all['heading1'].align='right';" />
例1(这个可以让你理解文档中哪些是对象)
οnclick=" document.all['heading1'].align='left';" />
<input type="button" value="Align Center"
οnclick=" document.all['heading1'].align='center';" />
<input type="button" value="Align Right"
οnclick=" document.all['heading1'].align='right';" />
例1(这个可以让你理解文档中哪些是对象)
<!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>
<title> Document.All Example</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<h1>Example Heading</h1>
<hr />
<p>This is a <em>paragraph</em>. It is only a <em>paragraph.</em></p>
<p>Yet another <em>paragraph.</em></p>
<p>This final <em>paragraph</em> has <em id="special">special emphasis.</em></p>
<hr />
<script type="text/javascript">
<!--
var i,origLength;
origLength = document.all.length;
document.write(' document.all.length='+origLength+"<br />");
for (i = 0; i < origLength; i++)
{
document.write(" document.all["+i+"]="+ document.all[i].tagName+"<br />");
}
//-->
</script>
</body>
</html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Document.All Example</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<h1>Example Heading</h1>
<hr />
<p>This is a <em>paragraph</em>. It is only a <em>paragraph.</em></p>
<p>Yet another <em>paragraph.</em></p>
<p>This final <em>paragraph</em> has <em id="special">special emphasis.</em></p>
<hr />
<script type="text/javascript">
<!--
var i,origLength;
origLength = document.all.length;
document.write(' document.all.length='+origLength+"<br />");
for (i = 0; i < origLength; i++)
{
document.write(" document.all["+i+"]="+ document.all[i].tagName+"<br />");
}
//-->
</script>
</body>
</html>
输出结果:
document.all.length=394
document.all[0]=!
document.all[1]=HTML
document.all[2]=HEAD
document.all[3]=TITLE
document.all[4]=META
document.all[5]=META
document.all[6]=META
document.all[7]=META
document.all[8]=META
document.all[9]=META
document.all[10]=LINK
document.all[11]=LINK
document.all[12]=LINK
document.all[13]=!
document.all[14]=META
document.all[15]=META
document.all[16]=META
document.all[17]=META
document.all[18]=META
document.all[19]=META
document.all[20]=META
document.all[21]=!
document.all[22]=BODY
document.all[23]=FORM
document.all[24]=DIV
document.all[25]=INPUT
document.all[26]=!
document.all[27]=STYLE
document.all[28]=SCRIPT
document.all[0]=!
document.all[1]=HTML
document.all[2]=HEAD
document.all[3]=TITLE
document.all[4]=META
document.all[5]=META
document.all[6]=META
document.all[7]=META
document.all[8]=META
document.all[9]=META
document.all[10]=LINK
document.all[11]=LINK
document.all[12]=LINK
document.all[13]=!
document.all[14]=META
document.all[15]=META
document.all[16]=META
document.all[17]=META
document.all[18]=META
document.all[19]=META
document.all[20]=META
document.all[21]=!
document.all[22]=BODY
document.all[23]=FORM
document.all[24]=DIV
document.all[25]=INPUT
document.all[26]=!
document.all[27]=STYLE
document.all[28]=SCRIPT
.........................................
..........................................
document.all[388]=EM
document.all[389]=EM
document.all[390]=DIV
document.all[391]=HR
document.all[392]=P
document.all[393]=SCRIPT
document.all[389]=EM
document.all[390]=DIV
document.all[391]=HR
document.all[392]=P
document.all[393]=SCRIPT