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

How to set value attribute in javascript

青灯夜游
Release: 2023-01-05 16:07:42
Original
11566 people have browsed it

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.

How to set value attribute in javascript

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>
Copy after login

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
Copy after login
  • Return attribute value

attribute.value
Copy after login

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!

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