Home  >  Article  >  Web Front-end  >  How to change the value of input box in javascript

How to change the value of input box in javascript

青灯夜游
青灯夜游Original
2021-07-16 14:43:1317194browse

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>

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

[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!

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