JavaScript Simple Calculator Production

Example of this article shared the specific code of JavaScript implementation of simple calculator for everyone, for all reference, the specific content is as follows

finished map

JavaScript简易计算器制作

This simple Calculator can only achieve + – * / operation

Before we do, we must first clarify ideas, look at the picture, if you want to achieve such a simple calculator, we need two input boxes Store two values ​​we need to make operations, a drop-down box to select what is going to do, a button to implement the start operation, one input box to save our calculated value!

First, we make these elements needed in Body

      +   -     =        You can start with you, easy to use 
Next is the most important Javascript place


/ / Get the element VAR INPT1 = Document.GtelementByid (“IPT1”); var inpt2 = document.getlementById (“ipt3); var inpt3 = document.getlementbyid (” ipt3 “); var selt = document.getlementByid (” SLT “); var butn = document.getlementById (” btn “); // Add a click event to add click event button.onclick = fUNCTION () {// assigns VALUE values ​​of three input boxes to variables T1, T2, T3, VAR T1 = PARSEFLOAT (ipt1.value); var T2 = parsefloat (ipt2.value); var T3 = PARSEFLOAT (IPT3 .value); // Defines a result variable to store the result var endValue; // Write an operation statement switch (sl.Value) {case “+”: endValue = t1 + t2; break; case “-” : EndValue = T1 – T2; Break; Case “*”: endvalue = t1 * t2; break; case “/”: endvalue = t1 / t2; break; default: endValue = T1 + T2; Break;} // will result Play the result input box’s value value, display inpt3.value = endValue on the page;}
     Such a simple page calculator it is done.   The above is all the content of this article, I hope to help everyone, I hope everyone will support Tumi Cloud. 
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment