Returns a reference to the collection of elements contained by the object. dhtml语法 [ collAll
= ] object.all | [ oObject = ] object.all(vIndex [, iSubIndex]) |
DHTML可能的值 collAll | Array of elements contained by the object. | oObject | Reference to an individual item in the array of elements contained by the object. | vIndex | Required. Integer or string that specifies the element or collection to retrieve. If this parameter is an integer, the method returns the element in the collection at the given position, where the first element has value 0, the second has 1, and so on. If this parameter is a string and there is more than one element with the name or id property equal to the string, the method returns a collection of matching elements. | isubindex | optional. position of an element to retrieve. this parameter is used when vindex is a string. the method uses the string to construct a collection of all elements that have a name or id property equal to the string, and then retrieves from this collection the element at the position specified by isubindex. |
members table
The following table lists the members exposed by the
all
object. Click a tab on the left to choose the type of member you want to view. Attributes/Properties Property | Description |
---|
length |
Sets or retrieves the number of objects in a collection. |
Methods Method | Description |
---|
item |
Retrieves an object from the all collection or various other collections. | nameditem |
Retrieves an object or a collection from the specified collection. | tags |
Retrieves a collection of objects that have the specified HTML tag name. | urns |
Retrieves a collection of all objects to which a specified behavior is attached. |
remarks the all collection includes one element object for each valid html tag. if a valid tag has a matching end tag, both tags are represented by the same element object. the collection returned by the document's all collection always includes a reference to the html, head, and title objects regardless of whether the tags are present in the document. if the body tag is not present, but other html tags are, a body object is added to the all collection. if the document contains invalid or unknown tags, the collection includes one element object for each. unlike valid end tags, unknown end tags are represented by their own element objects. the order of the element objects is the html source order. although the collection indicates the order of tags, it does not indicate hierarchy. the name property only applies to some elements such as form elements. if the vindex is set to a string matching the value of a name property in an element that the name property does not apply, then that element will not be added to the collection.
Examples
This example, in Microsoft® JScript® (compatible with ECMA 262 language specification), shows how to display the names of all tags in the document in the order the tags appear in the document. for(i = 0; i < document.all.length; i++){
alert(document.all(i).tagName);
}
This example, also in JScript, shows how to use the item method on the all collection to retrieve all element objects for which the name property or id attribute is set to sample. depending on the number of times the name or id is defined in the document, the item method returns null, a single element object, or a collection of element objects. the value of the length property of the collection determines whether item returns a collection or a single object. 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);
}
}
是否符合公共标准
There is no public standard that applies to this collection.
Applies To |
A,
ACRONYM,
ADDRESS,
APPLET,
AREA,
B,
BASE,
BASEFONT,
BDO,
BGSOUND,
BIG,
BLOCKQUOTE,
BODY,
BUTTON,
CAPTION,
CENTER,
CITE,
CODE,
COL,
COLGROUP,
CUSTOM,
DD,
DEL,
DFN,
DIR,
DIV,
DL,
document,
DT,
EM,
EMBED,
FIELDSET,
FONT,
FORM,
FRAME,
FRAMESET,
HEAD,
hn,
HR,
HTML,
I,
IFRAME,
IMG,
INS,
KBD,
LABEL,
LEGEND,
LI,
LINK,
LISTING,
MAP,
MARQUEE,
MENU,
OBJECT,
OL,
P,
PLAINTEXT,
PRE,
Q,
S,
SAMP,
SCRIPT,
SELECT,
SMALL,
SPAN,
STRIKE,
STRONG,
SUB,
SUP,
TABLE,
TBODY,
TD,
TEXTAREA,
TFOOT,
TH,
THEAD,
TITLE,
TR,
TT,
U,
UL,
VAR,
XMP | |
|