Home >Web Front-end >Front-end Q&A >What is the usage of value in JavaScript

What is the usage of value in JavaScript

WBOY
WBOYOriginal
2022-02-08 11:08:417605browse

In JavaScript, the value attribute can set or return the default value of the text field, and the syntax is "attribute.value=value" or "attribute.value".

What is the usage of value in JavaScript

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What is the usage of value in JavaScript

The value attribute can set the default value of the text field.

Syntax:

Set attribute value

attribute.value=value

Return attribute value

attribute.value

Return value: String, representing the value of the attribute.

The example is as follows:

<html>
<head>
<script type="text/javascript">
function alertValue()
  {
  alert(document.getElementById("password1").value)
  }
</script>
</head>
<body>
<form>
<input type="password" id="password1" value="thgrt456" />
<input type="button" id="button1" onclick="alertValue()" value="Show default value" />
</form>
</body>
</html>

Output result:

What is the usage of value in JavaScript

##After clicking the button:

What is the usage of value in JavaScript

Related recommendations:

javascript learning tutorial

The above is the detailed content of What is the usage of value 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