Home  >  Article  >  Web Front-end  >  How to implement click plus one in javascript

How to implement click plus one in javascript

WBOY
WBOYOriginal
2022-01-19 11:23:094131browse

Method: 1. Bind the click event to the button element and specify the time processing function; 2. In the event processing function, use the " " incremental operator to achieve the calculation plus one effect, the syntax is "specify element object.value;".

How to implement click plus one in javascript

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

How to implement click plus one in javascript

#If you want to use JavaScript to implement click plus one, you can use the " "incremental operator.

The example is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <input type="text" value="0"><br><br>
    <input type="submit" value="加一">
    <script type="text/javascript">
        var text = document.getElementsByTagName(&#39;input&#39;)[0];
        var add = document.getElementsByTagName(&#39;input&#39;)[1];
        add.onclick = function numberadd(){
            text.value++;  
        }
    </script>
</body>
</html>

Output result:

How to implement click plus one in javascript

Related recommendations: javascript learning tutorial

The above is the detailed content of How to implement click plus one 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