SoFunction
Updated on 2025-03-03

Other Objects in JavaScript

anchors[]; links[]; Link Connection object
Usage: [[x]]; [[x]]; <anchorId>; <linkId>
is an array that contains all anchor tags in the document (including the <a> tags of the name attribute). In the order in the document, a subscript is defined for each anchor tag starting from 0.
It is also an array that contains all the connection marks in the document (including the <a> mark of the href attribute and the <area> mark in the <map> mark segment). In the order in the document, a subscript is defined for each connection mark starting from 0.
If a <a> tag has both a name attribute and a href attribute, it is both an Anchor object and a Link object.
In IE, if the "" attribute is added to the <a> tag, the <a> object is assigned an identity (ID). When calling this object, you only need to use "<id>". Many document components can use this method to assign IDs, but be careful not to have two IDs the same.
anchors and links as arrays have properties and methods of arrays. A single Anchor object has no attributes; the properties of a single Link object are shown below.

property
protocol; hostname; port; host; pathname; hash; search; href same as the location object.
target Return/Specify the connection’s target window (string), which is the same as the target  attribute in the <a> tag.
event
onclick; onmouseover; onmouseout; onmousedown; onmouseup

applets[] Java applet object It is an array containing all Applet objects (Java applets) in the document. As an array, there are properties and methods of arrays. Regarding the properties and methods of a single Applet object, I quote a sentence: "Applet object inherits all public properties and methods of the Java applet." (Original English sentence: The Applet object inherits all public properties of the Java applet./The Applet object inherits all public methodss of the Java applet.) Because I hate Java applets, I am not interested in its “public” and “private” issues, so I didn’t discuss it.
embeds[] Plugin object It is an array containing all plugins (<embed> tags) in the document. Because each plug-in is different, each Embed object also has different properties and methods.
forms[]; Form Form object [] is an array containing all forms (<form>) in the document. To quote a single form, you can use [x], but generally speaking, people will do this: add the "name="..."" attribute to the <form> tag, and then use "document.<form name>" to reference it directly.

Properties of Form object
name Returns the name of the form, that is, the <form name="..."> attribute.
action Return/set the form’s submission address, that is, the <form action="..."> attribute.
method Return/set the form’s submission method, that is, the <form method="..."> attribute.
target Return/set the window returned after the form is submitted, that is, the <form target="..."> attribute.
encoding Return/set the encoding method of the form submission content, that is, the <form enctype="..."> attribute.
length Returns the number of elements contained in the form.
method
reset() Reset the form. This is the same as pressing the Reset button.
submit() Submit the form. This is the same as pressing the Submit button.
event
onreset; onsubmit

The following are all element objects of the form from "Button" to "Textarea".
The Button button object is specified by "<input type="button">". To refer to a Button object, you can use "<Document Object>.<Form Object>.<Button Name>". <button name> refers to the value of the "name="..."" attribute in the <input> tag. This method can be used to refer to any form element.

property
name Return/set the element name specified by <input name="...">.
value Return/set the value of the element specified with <input value="...">.
form returns the form object containing this element.
method
blur() removes focus from the object.
focus() allows the object to gain focus.
click() simulates the mouse clicking on the object.
event
onclick; onmousedown; onmouseup

Checkbox checkbox object is specified by "<input type="checkbox">".

property
name Return/set the element name specified by <input name="...">.
value Return/set the value of the element specified with <input value="...">.
form returns the form object containing this element.
checked Return/set whether the checkbox object is selected. This is a boolean value.
defaultChecked Return/set whether the check box object is selected by default. This is a boolean value.
method
blur() removes focus from the object.
focus() allows the object to gain focus.
click() simulates the mouse clicking on the object.
event
onclick

elements[]; Element Form Element Object <Form Object>.elements is an array that contains all objects of the form. Generally, we do not use this array, but directly refer to each specific object.
Hidden Objects are specified by "<input type="hidden">".

property
name Return/set the element name specified by <input name="...">.
value Return/set the value of the element specified with <input value="...">.
form returns the form object containing this element.

Password Password input area object is specified by "<input type="password">".

property
name Return/set the element name specified by <input name="...">.
value Return/set the current value in the password input area.
defaultValue Returns the default value specified with <input value="...">.
form returns the form object containing this element.
method
blur() removes focus from the object.
focus() allows the object to gain focus.
select() Select all text in the password input area.
event
onchange

Radio Single-selected domain object Specified by “<input type="radio">”. A group of Radio objects have a common name (name attribute), which becomes an array. To access a single Radio object, use: [x].

Properties of a single Radio object
name Return/set the element name specified by <input name="...">.
value Return/set the value of the element specified with <input value="...">.
form returns the form object containing this element.
checked Return/set whether the single-select domain object is selected. This is a boolean value.
defaultChecked Return/set whether the object is selected by default. This is a boolean value.
method
blur() removes focus from the object.
focus() allows the object to gain focus.
click() simulates the mouse clicking on the object.
event
onclick

Reset Reset button object Specified by “<input type="reset">”. Because Reset is also a button, there are also properties and methods of Button object. As for the "onclick" event, it is generally replaced by onreset of the Form object.
Select Select area (drop-down menu, list) object Specified by “<select>”.

property
name Return/set the element name specified by <input name="...">.
length Returns the number of options under the Select object.
selectedIndex Returns the subscript of the selected option. This subscript is the position of the option in the options[] array. If the Select object allows multiple selections, the subscript of the first selected option is returned.
form returns the form object containing this element.
method
blur() removes focus from the object.
focus() allows the object to gain focus.
event
onchange

options[]; Option Select Object options[] is an array containing Option objects under the same Select object. The Option object is specified by "<options>" under "<select>".

options[] Array properties
length; selectedIndex The same attribute as the Select object to which it belongs.
Properties of a single Option object
text Return/Specify the text displayed by the Option object
value Returns/Specify the value of the Option  object, which is consistent with <options value="...">.
index returns the index of the Option object. There is nothing to say about this, because to specify a specific Option object, you must first know the subscript of the object. This property seems useless.
selected Return/Specify whether the object is selected. By specifying true or false, you can dynamically change the selected item.
defaultSelected Returns whether the object is selected by default. true / false.

Submit button object is specified by "<input type="submit">. Because Submit is also a button, there are also properties and methods of the Button object. As for the "onclick" event, onsubmit of the Form object is generally replaced.
Text Text box object Specified by “<input type="text">”. The Password object is also a type of Text object, so all the properties, methods and events of the Password object are available.
Textarea Multi-line text input area object is specified by "<textarea>". All properties, methods and events of Textarea objects are the same as Text objects, that is, they are the same as Password objects.
images[]; Image Image [] is an array containing all the pictures in the document (<img>). To quote a single image, you can use [x]. If an image contains the "name" attribute, that is, a picture is defined in the format "<img name="...">", you can use the method "['...']" to quote the image. In IE, if an image contains an ID attribute, that is, a picture is defined in the format "<img >", you can directly use "<imageID>" to reference the picture.

Properties of a single Image object
name; src; lowsrc; width; height; vspace; hspace; border These attributes are the same as the attributes of the same name in the <img> tag. In Netscape, except for the src attribute, other attributes (almost all) cannot be changed. Even if they are changed, the effect cannot be displayed in the document. The most useful thing about these attributes is src. By assigning values ​​to the src attribute, you can change pictures in real time.
event
onclick
Image object not displayed in the document
The Image object not displayed in the document is defined using the var statement:

var myImage = new Image(); or
var myImage = new Image(<image address string>);

Then you can treat myImage variables like normal Image objects. However, since it is not displayed in the document, the following properties: lowsrc, width, height, vspace, hspace, border are of no use. Generally, there is only one use of this kind of object: preload. Because when assigning the src attribute of the object, the entire document reading and JavaScript running are suspended, allowing the browser to concentrate on reading the pictures. After reading the picture before it is read, the image is Copy in the browser cache. When the picture is really about to be placed in the document, the picture can be displayed immediately. There are often some image connections in web pages today. When the mouse points to it, the image is replaced with another image, and they all pre-read the image first.
JavaScript example of pre-read images

var imagePreload = new Image();
 = '';
 = '';
 = '';

The above examples are suitable for pre-reading a small number of pictures.

function imagePreload() {
  var imgPreload = new Image();
  for (i = 0; i < ; i++) {
     = arguments[i];
  }
}
imagePreload('', '', '', '', '');

The above examples are suitable for pre-reading a large number of pictures.