--- title: HTMLInputElement slug: Web/API/HTMLInputElement tags: - API - HTML DOM - Interface - NeedsNewLayout - NeedsTranslation - Reference - TopicStub translation_of: Web/API/HTMLInputElement ---
A interface HTMLInputElement fornece propriedades e métodos especiais (além da interface regular {{domxref ("HTMLElement")}}) que também tem disponível por herança) para manipular o layout e a apresentação dos elementos de entrada.
Inherits propriedades dos parentes, {{domxref("HTMLElement")}}.
Inherits methods from its parent, {{domxref("HTMLElement")}}.
Name & Arguments | Return | Description |
---|---|---|
blur() |
void |
Removes focus from input; keystrokes will subsequently go nowhere. |
checkValidity () |
{{jsxref("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. |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatGeckoDesktop(1.0)}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
autocomplete & autofocus properties |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
files property |
{{CompatVersionUnknown}} | {{CompatGeckoDesktop(1.9)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
multiple property |
{{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.9.2")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
indeterminate property |
{{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
list property |
{{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
formAction , formEncType , formMethod , formTarget properties |
{{CompatVersionUnknown}} | {{CompatGeckoDesktop(2)}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
formNoValidate , validationMessage , validity , willValidate properties and setCustomValidity() and checkValidity() methods. |
{{CompatVersionUnknown}} | {{CompatGeckoDesktop(2)}} | 10 | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
pattern , placeholder , required properties |
{{CompatVersionUnknown}} | {{CompatGeckoDesktop(2)}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
height and weight properties |
{{CompatVersionUnknown}} | {{CompatGeckoDesktop(16)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
labels property |
{{CompatChrome(14.0)}} | {{CompatNo}} ({{bug("556743")}}) | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
min , max , and step for <input type="number"> |
{{CompatVersionUnknown}} | Experimental, and without specific UI, since {{CompatGeckoDesktop(16)}}: behind the pref dom.experimental_forms |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatVersionUnknown}} |
stepUp and stepDown methods |
{{CompatUnknown}} | Experimental since {{CompatGeckoDesktop(16)}}: behind the pref dom.experimental_forms There are still differences with the latest spec: {{bug(835773)}} |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
min , max , and step properties for <input type="range"> |
{{CompatVersionUnknown}} | {{CompatGeckoDesktop(23)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatVersionUnknown}} |
min , max , and step properties for <input type="date"> |
{{CompatVersionUnknown}} | Experimental, and without specific UI, since {{CompatGeckoDesktop(20)}}: behind the pref dom.experimental_forms |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatVersionUnknown}} |
min , max , and step properties for other date-related type values |
{{CompatVersionUnknown}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatVersionUnknown}} |
mozGetFileNameArray() and mozSetFileNameArray() methods {{non-standard_inline}} |
{{CompatNo}} | {{CompatGeckoDesktop("1.9.2")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
mozSetFileArray() method {{non-standard_inline}} |
{{CompatNo}} | {{CompatGeckoDesktop("38")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
autocapitalize |
{{CompatChrome(43.0)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile(1.0)}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
autocapitalize | {{CompatNo}} | {{CompatChrome(43.0)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatChrome(43.0)}} |