Compile a simple calculator in JavaScript and write it in javascript.
This example describes how to compile the code of a simple calculator in JavaScript. Share it with you for your reference. The details are as follows:
The running effect is as follows:
The Code is as follows:
<! DOCTYPE html>
Js Code:
<Script> var num = 0; // define the first input data function jsq (num) {// obtain the current input if (num = "%") {document. getElementById ('screenname '). value = Math. round (document. getElementById ('screenname '). value)/100;} else {document. getElementById ('screenname '). value + = document. getElementById (num ). value ;}} function eva () {// calculate the input result document. getElementById ("screenName "). value = eval (document. getElementById ("screenName "). value);} function clearNum () {// clear 0 document. getElementById ("screenName "). value = null; document. getElementById ("screenName "). focus ();} function tuiGe () {// return var arr = document. getElementById ("screenName"); arr. value = arr. value. substring (0, arr. value. length-1) ;}</script>
A simple calculator is implemented in this way. You can also use javascript to write a calculator, hoping to help you learn it.