--- title: HTMLInputElement slug: Web/API/HTMLInputElement translation_of: Web/API/HTMLInputElement ---
Интерфейс HTMLInputElement
предоставляет специальные свойства и методы (расширяющие интерфейс {{domxref("HTMLElement")}} который также доступен через наследование) для управления размещением и отображением элементов input.
Наследует свойства своего родителя, {{domxref("HTMLElement")}}.
Название | Тип | Описание |
---|---|---|
accept |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("accept", "input") }} HTML attribute, containing comma-separated list of file types accepted by the server when {{htmlattrxref("type","input")}} is file . |
accessKey |
{{domxref("DOMString")}} | A single character that switches input focus to the control. |
align {{obsolete_inline}} |
{{domxref("DOMString")}} | Alignment of the element. |
alt |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("alt", "input") }} HTML attribute, containing alternative text to use when {{htmlattrxref("type","input")}} is image. |
autocapitalize {{experimental_inline}} |
{{domxref("DOMString")}} | Defines capitalization behavior for user input. Valid values are none , off , characters , words , or sentences . |
autocomplete |
{{domxref("DOMString")}} | Reflects the {{htmlattrxref("autocomplete", "input")}} HTML attribute, indicating whether the value of the control can be automatically completed by the browser. Ignored if the value of the {{htmlattrxref("type","input")}} attribute is hidden, checkbox, radio, file, or a button type (button, submit, reset, image). Possible values are:
|
autofocus |
{{domxref("Boolean")}} | Reflects the {{ htmlattrxref("autofocus", "input") }} 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 {{htmlattrxref("autofocus","input")}} attribute. It cannot be applied if the {{htmlattrxref("type","input")}} attribute is set to hidden (that is, you cannot automatically set focus to a hidden control). |
checked |
{{domxref("Boolean")}} | The current state of the element when {{htmlattrxref("type","input")}} is checkbox or radio . |
defaultChecked |
{{domxref("Boolean")}} | The default state of a radio button or checkbox as originally specified in HTML that created this object. |
defaultValue |
{{domxref("DOMString")}} | The default value as originally specified in HTML that created this object. |
dirName |
||
disabled |
{{domxref("Boolean")}} | Reflects the {{ htmlattrxref("disabled", "input") }} HTML attribute, indicating that the control is not available for interaction. The input values will not be submitted with the form. See also {{ htmlattrxref("readOnly", "input") }} |
files {{readonlyInline}} |
{{domxref("FileList")}} | A list of selected files. |
form {{readonlyInline}} |
{{domxref("HTMLFormElement")}} | The containing form element, if this element is in a form. If this element is not contained in a form element:
|
formAction |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("formaction", "input") }} HTML attribute, containing the URI of a program that processes information submitted by the element. If specified, this attribute overrides the {{ htmlattrxref("action", "form") }} attribute of the {{ HTMLElement("form") }} element that owns this element. |
formEncType |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("formenctype", "input") }} HTML attribute, containing the type of content that is used to submit the form to the server. If specified, this attribute overrides the {{ htmlattrxref("enctype", "form") }} attribute of the {{ HTMLElement("form") }} element that owns this element. |
formMethod |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("formmethod", "input") }} HTML attribute, containing the HTTP method that the browser uses to submit the form. If specified, this attribute overrides the {{ htmlattrxref("method", "form") }} attribute of the {{ HTMLElement("form") }} element that owns this element. |
formNoValidate |
{{domxref("Boolean")}} | Reflects the {{ htmlattrxref("formnovalidate", "input") }} HTML attribute, indicating that the form is not to be validated when it is submitted. If specified, this attribute overrides the {{ htmlattrxref("novalidate", "form") }} attribute of the {{ HTMLElement("form") }} element that owns this element. |
formTarget |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("formtarget", "input") }} 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 {{ htmlattrxref("target", "form") }} attribute of the {{ HTMLElement("form") }} element that owns this element. |
height |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("height", "input") }} HTML attribute, which defines the height of the image displayed for the button, if the value of {{htmlattrxref("type","input")}} is image. |
indeterminate |
{{domxref("Boolean")}} | Indicates that a checkbox is neither on nor off. |
labels {{readonlyInline}} |
{{domxref("NodeList")}} | A list of {{ HTMLElement("label") }} elements that are labels for this element. |
list |
{{domxref("HTMLElement")}} | Identifies a list of pre-defined options to suggest to the user. The value must be the id of a {{HTMLElement("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 {{htmlattrxref("type","input")}} attribute's value is hidden, checkbox, radio, file, or a button type. |
max |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("max", "input") }} HTML attribute, containing the maximum (numeric or date-time) value for this item, which must not be less than its minimum (min attribute) value. |
maxLength |
long |
Reflects the {{ htmlattrxref("maxlength", "input") }} 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. |
min |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("min", "input") }} HTML attribute, containing the minimum (numeric or date-time) value for this item, which must not be greater than its maximum ({{htmlattrxref("max","input")}} attribute) value. |
multiple |
Reflects the {{ htmlattrxref("multiple", "input") }} HTML attribute, indicating whether more than one value is possible (e.g., multiple files). | |
name |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("name", "input") }} HTML attribute, containing a name that identifies the element when submitting the form. |
pattern |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("pattern", "input") }} 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 {{htmlattrxref("title","input")}} attribute to describe the pattern to help the user. This attribute applies when the value of the {{htmlattrxref("type","input")}} attribute is text, search, tel, url or email; otherwise it is ignored. |
placeholder |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("placeholder", "input") }} 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 {{htmlattrxref("type","input")}} attribute is text, search, tel, url or email; otherwise it is ignored. |
readOnly |
{{domxref("Boolean")}} |
Reflects the {{ htmlattrxref("readonly", "input") }} HTML attribute, indicating that the user cannot modify the value of the control. |
required |
{{domxref("Boolean")}} | Reflects the {{ htmlattrxref("required", "input") }} HTML attribute, indicating that the user must fill in a value before submitting a form. |
selectionDirection |
{{domxref("DOMString")}} | 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." |
selectionEnd |
unsigned long |
The index of the end of selected text. |
selectionStart |
unsigned long |
The index of the beginning of selected text. When nothing is selected, this is also the caret position inside of the <input> element. |
size |
unsigned long |
Reflects the {{ htmlattrxref("size", "input") }} HTML attribute, containing size of the control. This value is in pixels unless the value of {{htmlattrxref("type","input")}} is text or password, in which case, it is an integer number of characters. {{ HTMLVersionInline(5) }} Applies only when {{htmlattrxref("type","input")}} is set to text, search, tel, url, email, or password; otherwise it is ignored. |
src |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("src", "input") }} HTML attribute, which specifies a URI for the location of an image to display on the graphical submit button, if the value of {{htmlattrxref("type","input")}} is image; otherwise it is ignored. |
step |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("step", "input") }} HTML attribute, which works with {{htmlattrxref("min","input")}} and {{htmlattrxref("max","input")}} 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. |
tabIndex |
long | The position of the element in the tabbing navigation order for the current document. |
type |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("type", "input") }} HTML attribute, indicating the type of control to display. See {{ htmlattrxref("type", "input") }} attribute of {{ HTMLElement("input") }} for possible values. |
useMap {{ obsolete_inline }} |
{{domxref("DOMString")}} | A client-side image map. |
validationMessage {{readonlyInline}} |
{{domxref("DOMString")}} | 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 ({{htmlattrxref("willValidate","input")}} is false ), or it satisfies its constraints. |
validity {{readonlyInline}} |
{{domxref("ValidityState")}} | The validity state that this element is in. |
value |
{{domxref("DOMString")}} |
Current value in 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. |
valueAsDate |
{{domxref("Date")}} | The value of the element, interpreted as a date, or null if conversion is not possible. |
valueAsNumber |
double |
The value of the element, interpreted as one of the following in order:
|
width |
{{domxref("DOMString")}} | Reflects the {{ htmlattrxref("width", "input") }} HTML attribute, which defines the width of the image displayed for the button, if the value of {{htmlattrxref("type","input")}} is image. |
willValidate |
{{domxref("Boolean")}} | Indicates whether the element is a candidate for constraint validation. It is false if any conditions bar it from constraint validation. |
Inherits methods from its parent, {{domxref("HTMLElement")}}.
Name & Arguments | Return | Description |
---|---|---|
blur() |
void |
Removes focus from input; keystrokes will subsequently go nowhere. |
checkValidity () |
{{domxref("Boolean")}} | Returns false if the element is a candidate for constraint validation, and it does not satisfy its constraints. In this case, it also fires an {{event("invalid")}} event at the element. It returns true if the element is not a candidate for constraint validation, or if it satisfies its constraints. |
click() |
void |
Simulates a click on the element. |
focus() |
void |
Focus on input; keystrokes will subsequently go to this element. |
mozSetFileArray(files) {{non-standard_inline}} |
void |
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. |
mozGetFileNameArray(length, filenames) {{non-standard_inline}} |
void |
Returns an array of all the file names from the input. |
mozSetFileNameArray(filenames, length) {{non-standard_inline}} |
void |
Sets the filenames for the files selected on the input. Not for use in frame scripts, because it accesses the filesystem. |
select() |
void |
Selects the input text in the element, and focuses it so the user can subsequently replace the whole entry. |
setCustomValidity(error) |
void |
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. |
setSelectionRange(selectionStart, selectionEnd, [optional] selectionDirection) |
void |
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. |
setRangeText(replacement, [optional] start, [optional] end, [optional] selectMode) |
void |
Replaces a range of text with the new text. Supported input types: text , search , url , tel , password. |
stepDown(n) |
void |
Decrements the {{htmlattrxref("value","input")}} by ({{htmlattrxref("step","input")}} * n ), where n defaults to 1 if not specified. Throws an INVALID_STATE_ERR exception:
|
stepUp(n) |
void |
Increments the {{htmlattrxref("value","input")}} by ({{htmlattrxref("step","input")}} * n ), where n defaults to 1 if not specified. Throws an INVALID_STATE_ERR exception:
|
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "tthe-input-element.html#the-input-element", "HTMLInputElement")}} | {{Spec2('HTML WHATWG')}} | No change from {{SpecName("HTML5 W3C")}} |
{{SpecName('HTML5 W3C', "forms.html#the-input-element", "HTMLInputElement")}} | {{Spec2('HTML5 W3C')}} | Technically, the tabindex and accesskey properties, as well as the blur() , click() , and focus() methods, are now defined on {{domxref("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() . |
{{SpecName('DOM2 HTML', 'html.html#ID-6043025', 'HTMLInputElement')}} | {{Spec2('DOM2 HTML')}} | The size property is now an unsigned long . The type property must be entirely given in lowercase characters. |
{{SpecName('DOM1', 'level-one-html.html#ID-6043025', 'HTMLInputElement')}} | {{Spec2('DOM1')}} | Initial definition. |
{{Compat("api.HTMLInputElement")}}