Home > Web Front-end > JS Tutorial > body text

How to change the value of input box in javascript

青灯夜游
Release: 2023-01-07 11:43:50
Original
17183 people have browsed it

In javascript, you can use the value attribute of HTML DOM to change the value of the input box. This attribute can set or return the value of the text field (input box or text box); the syntax format is "input box object. value="modify value";".

How to change the value of input box in javascript

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

javascript changes the value of the input box

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
	</head>
	<body>

		<input type="text" id="text1" value="Hello world!" />

		<p id="demo">点击按钮来改变input输入框的值。</p>

		<button onclick="myFunction()">试一下</button>

		<script>
			function myFunction() {
				document.getElementsByTagName("input")[0].value = "你好!";
			}
		</script>

	</body>
</html>
Copy after login

Output:

How to change the value of input box in javascript

Description :

The value attribute can set or return the value of the text field (input box or text box)

Syntax

textObject.value=text
Copy after login

[Recommended learning: javascript advanced Tutorial

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

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!