This article example shares the specific code of JavaScript to implement the addition calculator for your reference. The specific content is as follows Specific requirements: 1. Page layout: Specific implementation:<html> <head> <meta charset="utf-8"> <title>Calculator</title> <script> function myck(type){ var num1 = document.getElementById("num1"); var num2 = document.getElementById("num2"); if(type==1){ // Calculation operation var result = parseInt(num1.value) + parseInt(num2.value); alert(result); document.getElementById("resultDiv").innerText="Final calculation result:"+ result; }else if(type==2){ if(confirm("Is it cleared correctly?")){ // Clear num1.value = ""; num2.value = ""; document.getElementById("resultDiv").innerText=""; } } } </script> </head> <body> <div style="margin-top: 100px;margin-left: 500px;"> <span style="font-size: 60px;">Addition Calculator</span> </div> <div> <div class="innerDiv" style="margin-left: 550px;"> Number 1: <input id="num1" type="number" placeholder="Please enter number 1"> </div> </div> <div> <div class="innerDiv" style="margin-left: 550px;"> Number 2: <input id="num2" type="number" placeholder="Please enter number 2"> </div> </div> <div> <div style="margin-left: 600px;" class="innerDiv"> <input type="button" onclick="myck(1)" value="Calculate"> <input type="button" onclick="myck(2)" value="Clear"> </div> </div> <div id="resultDiv"> </div> </body> <style> .innerDiv{ margin-left: 420px; margin-top: 20px; } </style> </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:
|
<<: Solution to the automatic stop of MySQL service
>>: How to solve the problem that MySQL cannot start because it cannot create temporary files
Let’s take a look at what kind of charging animat...
1. What is SQL injection? Sql injection is an att...
Table of contents frame First-class error reporti...
At the end of last year, I replaced the opensuse ...
Table of contents 1. What is Function Anti-shake?...
background Recently, I executed a DML statement d...
As shown below: SELECT prod_name,prod_price FROM ...
Table of contents Overview Front-end knowledge sy...
This article uses an example to describe how MySQ...
When developing applications that use a database,...
1. Using it with redis will cause Netty startup c...
Mysql slow query explanation The MySQL slow query...
Table of contents 1. Understanding 2. Use 1. h() ...
Copy code The code is as follows: <style type=...
1. Installation The biggest feature of Terminator...