Home >Web Front-end >Front-end Q&A >What is the usage of value in JavaScript
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".
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
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:
##After clicking the button:Related recommendations:
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!