Home >Web Front-end >Front-end Q&A >How to implement click plus one in javascript
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;".
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('input')[0]; var add = document.getElementsByTagName('input')[1]; add.onclick = function numberadd(){ text.value++; } </script> </body> </html>
Output result:
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!