Home > Web Front-end > JS Tutorial > JavaScript example code to get/change the value of the text box_javascript skills

JavaScript example code to get/change the value of the text box_javascript skills

WBOY
Release: 2016-05-16 17:27:14
Original
1405 people have browsed it

Although and





This example shows two text boxes, one single-line and the other multi-line, and a button. When the button is clicked, an alert box will appear showing the contents of each text box.

You can also enter some content in the two text boxes and click the button.

Because the value attribute is a string, you can use any string attributes and methods. For example, you can use the length attribute to get the length of the text in the text box:
Copy the code The code is as follows:



Retrieving a Textbox Length Example









< ;/html>

In this example, the length attribute of value is used to determine the number of characters in each text box.

This value attribute can also be used to set new content for the text box:

Copy the code The code is as follows:



Changing a Textbox Value Example











In this example, clicking the button sets the first textbox to "first textbox" and the second textbox to "second textbox".
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template