Home >Web Front-end >JS Tutorial >How to get the value entered by the user in javascript

How to get the value entered by the user in javascript

青灯夜游
青灯夜游Original
2021-07-27 18:17:1310160browse

In JavaScript, you can use the value attribute to get the value entered by the user. This attribute can return the value in the input box or text box. The syntax format is "input box or text box object.value;".

How to get the value entered by the user in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Get the value of the input input

 var val = document.querySelector("input");
 val.value;//获得input输入的值

Get the value of the textarea input

 var val = document.querySelector("textarea");
 val.value;//获得textarea输入的值

Get the value of the selected drop-down list

<select id="city">
        <option value="nj">南京</option>
        <option value="sh">上海</option>
        <option value="bj">北京</option>
</select>
 var mySelect=document.querySelector("select#city");
 mySelect.value;

More programming related For knowledge, please visit: Introduction to Programming! !

The above is the detailed content of How to get the value entered by the user in javascript. 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