Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 17:27:141360browse

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".
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
Previous article:Solve the problem of connection error when js data contains plus sign and is transmitted to the background through ajax_javascript skillsNext article:Solve the problem of connection error when js data contains plus sign and is transmitted to the background through ajax_javascript skills

Related articles

See more