Home  >  Article  >  Java  >  How to get the value of input in js

How to get the value of input in js

(*-*)浩
(*-*)浩Original
2019-05-18 19:25:4640076browse

JS method to get the input value: first name from; then use the name of the form in JavaScript to call the value attribute of the input element in the form form; then assign the value to "a"; finally use js The "alert()" method can print it out.

How to get the value of input in js

In fact, there are many ways to obtain input values ​​using js. You can do it by just using selectors, but the steps are still the same. Yes, I will recommend 2 types for you today.

Method 1:

  
   
   
   
   
  
                 
        

This is one of the ways to get the input value of the web page. Give from a name and then call it with the name of the form in JavaScript. The value attribute of the input element in the form can get the value, assign the value to a, and finally print it out using the JavaScript alert() printing method.

Method 2:

  
   
   
   
   
  
                 
        

This is one of the ways to get the input value of the web page. Give from an ID and then use the form ID to call it in JavaScript. The value attribute of the input element in the form can get the value, assign the value to a, and finally print it out using the JavaScript alert() printing method.

The above is the detailed content of How to get the value of input in js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn