HTMLInputElement
Интерфейс HTMLInputElement
предоставляет специальные свойства и методы (расширяющие интерфейс HTMLElement
который также доступен через наследование) для управления размещением и отображением элементов input.
Properties
Наследует свойства своего родителя, HTMLElement
.
Название | Тип | Описание |
---|---|---|
accept |
DOMString |
Reflects the accept HTML
attribute, containing comma-separated list of file types accepted by the
server when type is
file .
|
accessKey |
DOMString |
A single character that switches input focus to the control. |
align |
DOMString |
Alignment of the element. |
alt |
DOMString |
Reflects the alt HTML
attribute, containing alternative text to use when
type is image.
|
autocapitalize
Экспериментальная возможность
|
DOMString |
Defines capitalization behavior for user input. Valid values are
none , off , characters ,
words , or sentences .
|
autocomplete |
DOMString |
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:
|
autofocus |
Boolean (en-US) |
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).
|
checked |
Boolean (en-US) |
The current state of the element when
type is checkbox or
radio .
|
defaultChecked |
Boolean (en-US) |
The default state of a radio button or checkbox as originally specified in HTML that created this object. |
defaultValue |
DOMString |
The default value as originally specified in HTML that created this object. |
dirName |
||
disabled |
Boolean (en-US) |
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
|
files Только для чтения |
FileList |
A list of selected files. |
form Только для чтения |
HTMLFormElement |
The containing form element, if this element is in a form. If this element is not contained in a form element: |
formAction |
DOMString |
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.
|
formEncType |
DOMString |
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.
|
formMethod |
DOMString |
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.
|
formNoValidate |
Boolean (en-US) |
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.
|
formTarget |
DOMString |
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.
|
height |
DOMString |
Reflects the height HTML
attribute, which defines the height of the image displayed for the
button, if the value of type is
image.
|
indeterminate |
Boolean (en-US) |
Indicates that a checkbox is neither on nor off. |
labels Только для чтения |
NodeList |
A list of <label> elements that are labels
for this element.
|
list |
HTMLElement |
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.
|
max |
DOMString |
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.
|
maxLength |
long |
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.
|
min |
DOMString |
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.
|
multiple |
Reflects the multiple HTML
attribute, indicating whether more than one value is possible (e.g.,
multiple files).
|
|
name |
DOMString |
Reflects the name HTML
attribute, containing a name that identifies the element when submitting
the form.
|
pattern |
DOMString |
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.
|
placeholder |
DOMString |
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.
|
readOnly |
Boolean (en-US) |
Reflects the |
required |
Boolean (en-US) |
Reflects the required HTML
attribute, indicating that the user must fill in a value before
submitting a form.
|
selectionDirection |
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 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.
HTML5 Applies only when
type is set to text, search,
tel, url, email, or password; otherwise it is ignored.
|
src |
DOMString |
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.
|
step |
DOMString |
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.
|
tabIndex |
long | The position of the element in the tabbing navigation order for the current document. |
type |
DOMString |
Reflects the type HTML
attribute, indicating the type of control to display. See
type attribute of
<input> for possible values.
|
useMap |
DOMString |
A client-side image map. |
validationMessage Только для чтения |
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
(willvalidate is
false ), or it satisfies its constraints.
|
validity Только для чтения |
ValidityState |
The validity state that this element is in. |
value |
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 |
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 |
DOMString |
Reflects the width HTML
attribute, which defines the width of the image displayed for the
button, if the value of type is
image.
|
willValidate |
Boolean (en-US) |
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
.
Name & Arguments | Return | Description |
---|---|---|
blur() |
void |
Removes focus from input; keystrokes will subsequently go nowhere. |
checkValidity () |
Boolean (en-US) |
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
invalid (en-US) 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
|
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
|
void |
Returns an array of all the file names from the input. |
mozSetFileNameArray(filenames, length)
Non-standard
|
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 value by
(step * n ), where
n defaults to 1 if not specified. Throws an
INVALID_STATE_ERR exception:
|
stepUp(n) |
void |
Increments the value by
(step * n ), where
n defaults to 1 if not specified. Throws an
INVALID_STATE_ERR exception:
|
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard Определение 'HTMLInputElement' в этой спецификации. |
Живой стандарт | No change from HTML5 |
HTML5 Определение 'HTMLInputElement' в этой спецификации. |
Рекомендация | 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 Определение 'HTMLInputElement' в этой спецификации. |
Устаревшая | 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 Определение 'HTMLInputElement' в этой спецификации. |
Устаревшая | Initial definition. |
Browser compatibility
BCD tables only load in the browser
See also
- HTML element implementing this interface:
<input>
.