HTMLInputElement

この翻訳は不完全です。英語から この記事を翻訳 してください。

The HTMLInputElement interface provides special properties and methods (beyond the regular HTMLElement interface it also has available to it by inheritance) for manipulating the layout and presentation of input elements.

Properties

Inherits properties from its parent, HTMLElement.

HTMLInputElement.accept
Is a DOMString that reflects the accept HTML attribute, containing comma-separated list of file types accepted by the server when type is file.
HTMLInputElement.accessKey
Is a DOMString containing a single character that switches input focus to the control when pressed.
HTMLInputElement.align
Is a DOMString representing the alignment of the element. Use CSS instead.
HTMLInputElement.alt
Is a DOMString that reflects the alt HTML attribute, containing alternative text to use when type is image.
HTMLInputElement.autocapitalize
Is a DOMString that defines the capitalization behavior for user input. Valid values are none, off, characters, words, or sentences.
HTMLInputElement.autocomplete
Is a DOMString that reflects the autocomplete HTML attribute, indicating whether the value of the control can be automatically completed by the browser. Ignored if the value of the type attribute is hidden, checkbox, radio, file, or a button type (button, submit, reset, image). Possible values are:
  • off: The user must explicitly enter a value into this field for every use, or the document provides its own auto-completion method; the browser does not automatically complete the entry.
  • on: The browser can automatically complete the value based on values that the user has entered during previous uses.
HTMLInputElement.autofocus
Is a Boolean that reflects the autofocus HTML attribute, which specifies that a form control should have input focus when the page loads, unless the user overrides it, for example by typing in a different control. Only one form element in a document can have the autofocus attribute. It cannot be applied if the type attribute is set to hidden (that is, you cannot automatically set focus to a hidden control).
HTMLInputElement.checked
Is a Boolean representing the current state of the element when type is checkbox or radio.
HTMLInputElement.defaultChecked
Is a Boolean representing the default state of a radio button or checkbox as originally specified in HTML that created this object.
HTMLInputElement.defaultValue
Is a DOMString representing the default value as originally specified in HTML that created this object.
HTMLInputElement.dirName
Is a
HTMLInputElement.disabled
Is a Boolean that reflects the disabled HTML attribute, indicating that the control is not available for interaction. The input values will not be submitted with the form. See also readonly 
HTMLInputElement.files Read only
Returns a FileList containing the list of selected files.
HTMLInputElement.form
Is a HTMLFormElement representing the containing form element, if this element is in a form. If this element is not contained in a form element, it is the id attribute of any <form> element in the same document. Even if the attribute is set on <input>, this property will be null, if it isn't the id of a <form> element.
HTMLInputElement.formAction
Is a DOMString that reflects the formaction HTML attribute, containing the URI of a program that processes information submitted by the element. If specified, this attribute overrides the action attribute of the <form> element that owns this element.
HTMLInputElement.formEncType
Is a DOMString that reflects the formenctype HTML attribute, containing the type of content that is used to submit the form to the server. If specified, this attribute overrides the enctype attribute of the <form> element that owns this element.
HTMLInputElement.formMethod
Is a DOMString that reflects the formmethod HTML attribute, containing the HTTP method that the browser uses to submit the form. If specified, this attribute overrides the method attribute of the <form> element that owns this element.
HTMLInputElement.formNoValidate
Is a Boolean that reflects the formnovalidate HTML attribute, indicating that the form is not to be validated when it is submitted. If specified, this attribute overrides the novalidate attribute of the <form> element that owns this element.
HTMLInputElement.formTarget
Is a DOMString that reflects the formtarget HTML attribute, containing a name or keyword indicating where to display the response that is received after submitting the form. If specified, this attribute overrides the target attribute of the <form> element that owns this element.
HTMLInputElement.height
Is aDOMString that reflects the height HTML attribute, which defines the height of the image displayed for the button, if the value of type is image.
HTMLInputElement.indeterminate
Is a Boolean that indicates that the checkbox is neither on nor off.
HTMLInputElement.labels Read only
Returns a live NodeList of <label> elements that are labels for this element.
HTMLInputElement.list Read only
Is a HTMLElement that identifies a list of pre-defined options to suggest to the user. The value must be the id of a <datalist> element in the same document. The browser displays only options that are valid values for this input element. This attribute is ignored when the type attribute's value is hidden, checkbox, radio, file, or a button type. The property may be null if no HTML element matches the criteria.
HTMLInputElement.max
Is a DOMString that reflects the max HTML attribute, containing the maximum (numeric or date-time) value for this item, which must not be less than its minimum (min attribute) value.
HTMLInputElement.maxLength
Is a long integer that reflects the maxlength HTML attribute, containing the maximum length of text (in Unicode code points) that the value can be changed to. The constraint is evaluated only when the value is changed

Note: If you set maxLength to a negative value programmatically, an exception will be thrown.

HTMLInputElement.min
Is a DOMString that reflects the min HTML attribute, containing the minimum (numeric or date-time) value for this item, which must not be greater than its maximum (max attribute) value.
HTMLInputElement.multiple
Is a Boolean that reflects the multiple HTML attribute, indicating whether more than one value is possible (e.g., multiple files).
HTMLInputElement.name
Is a DOMString that reflects the name HTML attribute, containing a name that identifies the element when submitting the form.
HTMLInputElement.pattern
Is a DOMString that reflects the pattern HTML attribute, containing a regular expression that the control's value is checked against. The pattern must match the entire value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is text, search, tel, url or email; otherwise it is ignored.
HTMLInputElement.placeholder
Is a DOMString that reflects the placeholder HTML attribute, containing a hint to the user of what can be entered in the control. The placeholder text must not contain carriage returns or line-feeds. This attribute applies when the value of the type attribute is text, search, tel, url or email; otherwise it is ignored.
HTMLInputElement.readOnly
Is a Boolean that reflects the readonly HTML attribute, indicating that the user cannot modify the value of the control.
HTML5This is ignored if the value of the type attribute is hidden, range, color, checkbox, radio, file, or a button type.
HTMLInputElement.required
Is a Boolean that reflects the required HTML attribute, indicating that the user must fill in a value before submitting a form.
HTMLInputElement.selectionDirection
Is a DOMString representing the direction in which selection occurred. This is "forward" if selection was performed in the start-to-end direction of the current locale, or "backward" for the opposite direction. This can also be "none" if the direction is unknown."
HTMLInputElement.selectionEnd
Is an unsigned long value that represents the index of the end of selected text.
HTMLInputElement.selectionStart
Is an unsigned long value that represents the index of the beginning of selected text. When nothing is selected, this is also the caret position inside of the <input> element.
HTMLInputElement.size
Is an unsigned long value that reflects the size HTML attribute, containing size of the control. This value is in pixels unless the value of type is text or password, in which case, it is an integer number of characters. Applies only when type is set to text, search, tel, url, email, or password; otherwise it is ignored.
HTMLInputElement.src
Is a DOMString that reflects the src HTML attribute, which specifies a URI for the location of an image to display on the graphical submit button, if the value of type is image; otherwise it is ignored.
HTMLInputElement.step
Is a DOMString that reflects the step HTML attribute, which works with min and max to limit the increments at which a numeric or date-time value can be set. It can be the string any or a positive floating point number. If this is not set to any, the control accepts only values at multiples of the step value greater than the minimum.
HTMLInputElement.type
Is a DOMString that reflects the type HTML attribute, indicating the type of control to display. See type attribute of <input> for possible values.
HTMLInputElement.useMap
Is a DOMString representing a client-side image map.
HTMLInputElement.validationMessage Read only
Returns a DOMString that represents a localized message that describes the validation constraints that the control does not satisfy (if any). This is the empty string if the control is not a candidate for constraint validation (willvalidate is false), or it satisfies its constraints.
HTMLInputElement.validity Read only
Returns a ValidityState that represents the validity stat that this element is in.
HTMLInputElement.value
Is a DOMString representing the current value of the control.

Note: for certain input types the returned value might not match the value the user has entered. For example, if the user enters a non-numeric value into an <input type="number">, the returned value might be an empty string instead.

HTMLInputElement.valueAsDate
Is a Date containing the value of the element, interpreted as a date, or null if conversion is not possible.
HTMLInputElement.valueAsNumber
Is a double value containing the value of the element, interpreted as one of the following in order:
  • a time value,
  • a number,
  • NaN if the conversion is not possible.
HTMLInputElement.webkitDirectory
Is a Boolean that reflects the webkitdirectory HTML attribute, which indicates if the input selects only directories and should display a specific file picker if possible.
HTMLInputElement.width
Is a DOMString that reflects the width HTML attribute, which defines the width of the image displayed for the button, if the value of type is image.
HTMLInputElement.willValidate
Is a Boolean that indicates whether the element is a candidate for constraint validation. It is false if any conditions bar it from constraint validation.

Methods

Inherits methods from its parent, HTMLElement.

HTMLInputElement.blur()
Removes focus from input; keystrokes will subsequently go nowhere.
HTMLInputElement.checkValidity()
Returns a Boolean that is false if the element is a candidate for constraint validation, and it does not satisfy its constraints. In this case, it also fires an invalid event at the element. It returns true if the element is not a candidate for constraint validation, or if it satisfies its constraints.
HTMLInputElement.click()
Simulates a click on the element.
HTMLInputElement.focus()
Focus on the input element; keystrokes will subsequently go to this element.
HTMLInputElement.mozSetFileArray()
Sets the files selected on the input to the given array of File objects.  This is an alternative to mozSetFileNameArray which can be used in frame scripts: a chrome script can open files as File objects and send them via message manager.
HTMLInputElement.mozGetFileNameArray()
Returns an array of all the file names from the input.
HTMLInputElement.mozSetFileNameArray()
Sets the filenames for the files selected on the input.  Not for use in frame scripts, because it accesses the filesystem.
HTMLInputElement.select()
Selects the input text in the element, and focuses it so the user can subsequently replace the whole entry.
HTMLInputElement.setCustomValidity()
Sets a custom validity message for the element. If this message is not the empty string, then the element is suffering from a custom validity error, and does not validate.
HTMLInputElement.setSelectionRange()
Selects a range of text in the element (but does not focus it). The optional selectionDirection parameter may be "forward" or "backward" to establish the direction in which selection was set, or "none" if the direction is unknown or not relevant. The default is "none". Specifying a selectionDirection parameter sets the value of the selectionDirection property.
HTMLInputElement.setRangeText()
Selects a range of text in the element (but does not focus it). The optional selectionDirection parameter may be "forward" or "backward" to establish the direction in which selection was set, or "none" if the direction is unknown or not relevant. The default is "none". Specifying a selectionDirection parameter sets the value of the selectionDirection property.
HTMLInputElement.setRangeText()
Decrements the value by (step * n), where n defaults to 1 if not specified. Throws an INVALID_STATE_ERR exception:
  • if the method is not applicable to for the current type value,
  • if the element has no step value,
  • if the value cannot be converted to a number,
  • if the resulting value is above the max or below the min
HTMLInputElement.setRangeText()
Increments the value by (step * n), where n defaults to 1 if not specified. Throws an INVALID_STATE_ERR exception:
  • if the method is not applicable to for the current type value.,
  • if the element has no step value,
  • if the value cannot be converted to a number,
  • if the resulting value is above the max or below the min.

Specifications

Specification Status Comment
WHATWG HTML Living Standard
The definition of 'HTMLInputElement' in that specification.
Living Standard No change from HTML5
HTML5
The definition of 'HTMLInputElement' in that specification.
Recommendation Technically, the  tabindex and accesskey properties, as well as the blur(), click(), and focus() methods, are now defined on HTMLElement.
The following properties are now obsolete: align and useMap.
The following properties have been added: autocomplete, autofocus, dirName, files, formAction, formEncType, formMethod, formNoValidate, formTarget, height, indeterminate, labels, list, max, min, multiple, pattern, placeholder, required, selectionDirection, selectionEnd, selectionStart, step, validationMessage, validity, valueAsDate, valueAsNumber, width, and willValidate.
The following methods have been added: checkValidity(), setCustomValidity(), setSelectionRange(), stepUp(), and stepDown().
Document Object Model (DOM) Level 2 HTML Specification
The definition of 'HTMLInputElement' in that specification.
Recommendation The size property is now an unsigned long. The type property must be entirely given in lowercase characters.
Document Object Model (DOM) Level 1 Specification
The definition of 'HTMLInputElement' in that specification.
Recommendation Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) 1.0 (1.7 or earlier) (Yes) (Yes) (Yes)
autocomplete & autofocus properties (Yes) (Yes) (Yes) (Yes) (Yes)
files property (Yes) 3.0 (1.9) 10 ? ?
multiple property (Yes) 3.6 (1.9.2) ? ? ?
indeterminate property ? (Yes) ? ? ?
list property ? (Yes) ? ? ?
formAction, formEncType, formMethod, formTarget properties (Yes) 4.0 (2) (Yes) (Yes) (Yes)
formNoValidate, validationMessage, validity, willValidate properties and setCustomValidity() and checkValidity() methods. (Yes) 4.0 (2) 10 (Yes) (Yes)
pattern, placeholder, required properties (Yes) 4.0 (2) (Yes) (Yes) (Yes)
height and weight properties (Yes) 16 (16) ? ? ?
labels property 14.0 No support (bug 556743) ? ? ?
min, max, and step for <input type="number"> (Yes) Experimental, and without specific UI, since 16 (16): behind the pref dom.experimental_forms ? ? (Yes)
stepUp and stepDown methods ? Experimental since 16 (16): behind the pref dom.experimental_forms

There are still differences with the latest spec: bug 835773
? ? ?
min, max, and step properties for <input type="range"> (Yes) 23 (23) ? ? (Yes)
min, max, and step properties for <input type="date"> (Yes) Experimental, and without specific UI, since 20 (20): behind the pref dom.experimental_forms ? ? (Yes)
min, max, and step properties for other date-related type values (Yes) No support ? ? (Yes)
mozGetFileNameArray() and mozSetFileNameArray() methods No support 3.6 (1.9.2) No support No support No support
mozSetFileArray() method No support 38 (38) No support No support No support
autocapitalize 43.0 ? ? ? ?
Feature Android Android Webview Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support (Yes) (Yes) 1.0 (1.0) (Yes) (Yes) (Yes) (Yes)
autocapitalize No support 43.0 ? ? ? ? 43.0

See also

  • HTML element implementing this interface: <input>.

ドキュメントのタグと貢献者

 このページの貢献者: jdanyow
 最終更新者: jdanyow,