HTML DOM Select 对象

Select Object

The Select object represents the HTML <select> element.

Access Select Object

You can access the <select> element using getElementById():

var x = document.getElementById("mySelect");

Try It Yourself

Tip:You can also access the Select object by iterating over the form's elements collection.

Create Select Object

You can create a <select> element using the document.createElement() method:

var x = document.createElement("SELECT");

Try It Yourself

Select object collection

Collection Description
options Return a collection of all options in the dropdown list.

Select object properties

Properties Description
autofocus Set or return whether the dropdown list should automatically focus when the page is loaded.
disabled Set or return whether the dropdown list should be disabled.
form Return a reference to the form containing the dropdown list.
length Return the number of <option> elements in the dropdown list.
multiple Set or return whether multiple options can be selected from the dropdown list.
name Set or return the name attribute value of the dropdown list.
selectedIndex Set or return the index of the selected option in the dropdown list.
size Set or return the size attribute value of the dropdown list.
type Return what type of form element the dropdown list is.
value Set or return the value of the selected option in the dropdown list.

Select object methods

Method Description
add() Add options to the dropdown list.
checkValidity()
remove() Remove options from the dropdown list.

Standard properties and events

The Select object supports both standardsPropertiesAndEvents.

Related Pages

HTML Tutorial:HTML 表单

HTML Reference Manual:HTML <select> 标签