The JavaScript code of the white concise style calculator is a beautifully concise calculator JS code plug-in webpage special effect, software application, background application JS calculator plug-in code free download. The calculator code in this article is very simple. you can easily apply this webpage special effect to your project.
HTML
First, we place an input box and multiple calculator buttons on the webpage.
C
+/-
%
←
7
8
9
+
-
4
5
6
×
÷
1
2
3
ײ
√
0
.
=
Js
Perform the following operations based on the operation type:
function operator(type) { switch (type) { case "clear": input.value = "0"; _string.length = 0; /*document.getElementById("ccc").innerHTML=""; for(i=0;i<_string.length;i++) { document.getElementById("ccc").innerHTML+=_string[i]+" " }*/ break; case "backspace": if (checknum(input.value) != 0) { input.value = input.value.replace(/.$/, ''); if (input.value == "") { input.value = "0"; } } break; case "opposite": if (checknum(input.value) != 0) { input.value = -input.value; } break; case "percent": if (checknum(input.value) != 0) { input.value = input.value / 100; } break; case "pow": if (checknum(input.value) != 0) { input.value = Math.pow(input.value, 2); } break; case "sqrt": if (checknum(input.value) != 0) { input.value = Math.sqrt(input.value); } break; case "plus": if (checknum(input.value) != 0) { _string.push(input.value); _type = "plus"input.value = "+"; input.name = "type"; } break; case "minus": if (checknum(input.value) != 0) { _string.push(input.value); _type = "minus"input.value = "-"; input.name = "type"; } break; case "multiply": if (checknum(input.value) != 0) { _string.push(input.value); _type = "multiply"input.value = "×"; input.name = "type"; } break; case "pide": if (checknum(input.value) != 0) { _string.push(input.value); _type = "pide"input.value = "÷"; input.name = "type"; } break; case "result": if (checknum(input.value) != 0) { _string.push(input.value); if (parseInt(_string.length) % 2 != 0) { _string.push(_string[_string.length - 2]) } if (_type == "plus") { input.value = parseFloat(result(_string)[0]) + parseFloat(result(_string)[1]); input.name = "type" } else if (_type == "minus") { input.value = parseFloat(result(_string)[0]) - parseFloat(result(_string)[1]); input.name = "type" } else if (_type == "multiply") { input.value = parseFloat(result(_string)[0]) * parseFloat(result(_string)[1]); input.name = "type" } else if (_type == "pide") { input.value = parseFloat(result(_string)[0]) / parseFloat(result(_string)[1]); input.name = "type" } break; } } }
The above is all the content of this article. I hope you will like it.