var inputEl = document.querySelector('[name="username"]'); var val = inputEl. value; console.log(val);
input attribute HTML5
property | value | description |
---|---|---|
accept | mime_type | Specifies the type of file to submit via file upload. |
align |
|
Deprecated. Specifies the alignment of the image input. |
alt | text | Define the image input Alt text. |
autocomplete |
|
Specifies whether to use the autocomplete function of the input field. |
autofocus | autofocus |
Determines whether the input field gets focus when the page loads. (not applicable to type=”hidden”) |
checked | checked | Specifies that this input element should be selected when it is first loaded. |
disabled | disabled | When the input element is loaded disable this element. |
form | formname | Specifies one or more forms to which the input field belongs. |
formaction | URL |
Overrides the form’s action attribute. (for type=”submit” and type=”image”) |
formenctype | see note |
Overrides the form’s enctype attribute. (for type=”submit” and type=”image”) |
formmethod |
|
overrides the method attribute of the form. (for type=”submit” and type=”image”) |
formnovalidate | formnovalidate |
Overrides the form’s novalidate attribute. If this attribute is used, no validation will be performed when the form is submitted. |
formtarget |
|
Overrides the form’s target attribute. (for type=”submit” and type=”image”) |
height |
|
Defines the height of the input field. (for type=”image”) |
list | datalist-id | Reference contains input A datalist of predefined options for the field. |
max |
|
Specifies the maximum value of the input field. Use with the “min” attribute to create a range of legal values. |
maxlength | number | Specifies the maximum length of characters in the input field. |
min |
|
Specifies the minimum value of the input field. Use with the “max” attribute to create a range of legal values. |
multiple | multiple | If this attribute is used, more than one value is allowed. |
name | field_name | Definition of the input element name. |
pattern | regexp_pattern |
Specifies the pattern or format of the value of the input field. For example, pattern=”[0-9]” means that the input value must be a number between 0 and 9. |
placeholder | text | Specifies hints to help users fill out input fields. |
readonly | readonly | specifies that the input field is read only. |
required | required | Indicates that the value of the input field is required. |
size | number_of_char | Define the input field width. |
src | URL | Define to submit button The URL of the image displayed in the form. |
step | number | specifies the legal number interval of the input word. |
type |
|
Specifies the type of input element. |
value | value | specifies the value of the input element. |
width |
|
Define the width of the input field. (Applicable to type=”image”) |
Recommended tutorial: “JS Tutorial”
The above is how JS gets the value of the input? For more details, please pay attention to other related articles on 1024programmer.com!