This article example shares the specific code of javascript to implement a simple calculator for your reference. The specific content is as follows Design a simple calculator Code <body> <a>First number</a> <input type="test" id="inputId1" value="" /><br/> <a>Second number</a> <input type="test" id="inputId2" value="" /><br/> <button onclick="cal('+')">+</button> <button onclick="cal('-')">-</button> <button onclick="cal('*')">*</button> <button onclick="cal('/')">/</button><br/> Calculation results <input type="test" id="resultId" value="" /> <script type="text/javascript"> // function add() { // console.log('add'); // var inputObj1 = document.getElementById('inputId1'); // var inputObj2 = document.getElementById('inputId2'); // var result = parseInt(inputObj1.value) + parseInt(inputObj2.value); // var resultObj = document.getElementById('result'); // resultObj.value = result; // console.log(result); // } function cal(type) { var inputObj1 = document.getElementById('inputId1'); var inputObj2 = document.getElementById('inputId2'); switch(type){ case '+': var result = parseInt(inputObj1.value) + parseInt(inputObj2.value); break; case '-': var result = parseInt(inputObj1.value) - parseInt(inputObj2.value); break; case '*': var result = parseInt(inputObj1.value) * parseInt(inputObj2.value); break; case '/': var result = parseInt(inputObj1.value) / parseInt(inputObj2.value); break; } var resultObj = document.getElementById('resultId'); resultObj.value = result; } </script> </body> </html> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Summary of basic SQL statements in MySQL database
>>: How to run Python script on Docker
Table of contents 1. Database Engine 1.1 View dat...
When shutting down the MySQL server, various prob...
Alignment issues like type="radio" and t...
Notes on installing MySQL database, share with ev...
Prerequisites 1. Docker has been installed on the...
KILL [CONNECTION | QUERY] processlist_id In MySQL...
Table of contents 1. Number in JavaScript 2. Math...
Effect Preview Press the "Click to Preview&q...
Today, I will answer these newbie questions: Build...
This article shares the specific code of JavaScri...
Putting aside databases, what is dialect in life?...
To install VMWare under Linux, you need to downlo...
Tab switching is also a common technology in proj...
Syn attack is the most common and most easily exp...
Table of contents Impact of full table scan on th...