1024programmer JavaScript How does JS get the value of input?

How does JS get the value of input?

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
  • left
  • right
  • top
  • middle
  • bottom
Deprecated. Specifies the alignment of the image input.
alt text Define the image input Alt text.
autocomplete
  • on
  • off
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
  • get
  • post

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
  • _blank
  • _self
  • _parent
  • _top
  • framename

Overrides the form’s target attribute.

(for type=”submit” and type=”image”)

height
  • pixels
  • %
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
  • number
  • date

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
  • number
  • date

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
  • button
  • checkbox
  • file
  • hidden
  • image
  • password
  • radio
  • reset
  • submit
  • text
Specifies the type of input element.
value value specifies the value of the input element.
width
  • pixels
  • %
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!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/how-does-js-get-the-value-of-input/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索