14.3.3 Access Form Control
A form is represented by an htmlformelement object in the Dom. In addition to the basic attributes and methods described above, this object also has the following common attributes.
Action: return the value of the action attribute of the form. This attribute is used to specify the submission address of the form. Read/write attributes.
Elements: returns an array composed of All Form Controls in the form. Use this array to access any form controls in the form. Read-only attribute.
Length: returns the number of form fields in the form. This attribute is equal to the value of elements. length. Read-only attribute.
Method: return the method attribute of the form. This attribute usually has two values: Post and get. The get method is used by default. This attribute is used to determine the form sending request method. Read/write attributes.
Target: used to determine the result window when a form is submitted. values include _ Self, _ parent, _ top, and _ blank. Read/write attributes.
In addition, the form object has the following two common methods.
Reset (): reset the form and set the values of all form fields to the initial values.
Submit (): submit a form.
The htmlformelement Access Form Control has the following 3 syntax.
Formobj. elements [Index]: return the nth Index Form Control in the form.
Formobj. elements ['elementname']: return the Form Control whose ID or name is elementname in the form.
Formobj. elementname: return the Form Control whose ID or name is elementname in the form.
14.3.4 options for accessing the list box and drop-down menu
Htmlselectelement represents a list box or drop-down menu. In addition to various attributes and methods of common HTML elements, the htmlselectelement object,
The following additional attributes are also supported.
Form: returns the form object of the list box and drop-down menu. Read-only attribute.
Length: returns the number of options in the list box and drop-down menu. The value of this attribute can be changed by adding or deleting the option of the list box. Read-only attribute.
Options: returns an array composed of the list box and all options in the drop-down list. Read-only attribute.
Selectdindex: returns the index of the selected option in the drop-down list. If multiple options are selected, only the index of the first selected option is returned. Read/write attributes.
Type: Type of the drop-down list. If multiple selections are allowed, select-multiple is returned. If multiple selections are not supported, select-one is returned.
The options attribute of htmlselectelement can directly access all list items in the list box and drop-down menu. You can access the specified list items by passing in the specified index. The syntax format is as follows.
Select. Options [Index]: returns the list box and the index + 1 option in the drop-down menu.
The options of the list box and drop-down menu are represented by the htmloptionelement object. In addition to the common attributes described above, this object also provides the following common attributes.
Form: returns the form object that contains the list box in which the option is located and the drop-down menu.
Defaultselected: returns whether this option is selected by default. Read-only attribute.
Index: returns the index of this option in the list box and drop-down menu. Read-only attribute. Of course, you can also change the index value of this option by adding or deleting the options in the list box.
Selected: returns whether this option is selected. By modifying this attribute, You can dynamically change whether this option is selected.
Text: return the text presented by this option, that is, the text between <option> and </option>. For htmloptionelement, this attribute is the same as the innerhtml attribute.
Value: return the value attribute of each option. You can set this attribute to change the value of the option.
14.3.5 Access Table lattice elements
Htmltableelement represents a table. In addition to the attributes and methods of common HTML elements, htmltableelement also supports the following additional attributes.
Caption: returns the title object of the table. You can modify this attribute to change the table title.
Htmlcollection rows: returns all table flights in the table. This attribute returns all table flights in the <thead>, <tfoot>, and <tbody> elements. Read-only attribute.
Table. Rows [Index]: returns the table row at index + 1 of the table.
Htmlcollection tbodies: returns an array composed of all <tbody> elements in the table.
Tfoot: returns the <tfoot> element in the table.
Fhead: returns all <thead> elements in the table.
Htmltablerowelement represents table rows. In addition to the attributes and methods of common HTML elements, the htmltablerowelement object also supports the following additional attributes.
Cells: returns an array of all cells in the row of the table. Read-only attribute.
Rowindex: returns the index value of the table row in the table. Read-only attribute.
Sectonrowindex: returns the index value of the table row on its <tbody>, <thead>, and other elements. Read-only attribute.
Htmltablecellelement indicates a cell. In addition to the attributes and methods of common HTML elements, the htmltablecellelement object also supports the following additional attributes.
Cellindex: returns the index value of the cell in the row of the table. Read-only attribute.
14.4 modify HTML elements
Modifying HTML elements is usually done by modifying the following common attributes.
Innerhtml: This attribute controls most HTML page elements, such as <div> and <TD>.
Value: This attribute controls the rendering content of form controls such as <input> and <textarea>.
Classname: modifies the CSS style of an HTML element. The valid value of this attribute is a class selector name.
Style: modifies the inline CSS style of HTML elements.
Options [Index]: assign values directly to the specified list items of the <SELECT> element. You can change the specified list items in the list box and drop-down menu.