How to set the value attribute in JavaScript: First use the document.getElementById() method to obtain the specified DOM object; then set it with the "DOM object.value="value";" statement.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript setting value
Some elements have value attributes, such as input, bottom, select, etc. You can use the value attribute to modify its value.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>修改value</title> </head> <body> <input type="text" name="hello" value="Hello krray" id="hello"> <script> var a=document.getElementById("hello"); alert( a.value); a.value="你好,小凯" </script> </body> </html>
HTML DOM value attribute
The value attribute is used to set or return the value of the attribute.
Syntax:
Set attribute value
attribute.value=value
Return attribute value
attribute.value
Return value: string, representing the value of the attribute.
【Recommended learning: javascript advanced tutorial】
The above is the detailed content of How to set value attribute in javascript. For more information, please follow other related articles on the PHP Chinese website!