Home > Back-end >  You understand the JSP bosses look at me!!!!!!!!
You understand the JSP bosses look at me!!!!!!!!

Time:09-21

How to create simple calculator website, as shown in the figure below

CodePudding user response:

Do two input box, a drop-down box, a button, js section for the value of the two input box, and the value of the drop-down box, and then according to the value of drop-down box to judge what to do operation, do a click on the submit event, to generate the following words

CodePudding user response:



Input operator:





Result: & lt; Span id="result" & gt;




<script>
The function calculate () {
//get operand 1
Var num1=parseFloat (document. GetElementById (" num1 "). The value).
//get operator
Var symbol=document. GetElementById (" symbol "). The value;
//get operand 2
Var num2=parseFloat (document. GetElementById (" num2 "). The value).

Operations//
Var result;
If (symbol==1) {
Result=num1 + + num2 + "=" + "+" (num1 + num2);
}
If (symbol==2) {
Result=num1 + "-" + num2 + "=" + (num1 - num2);
}
If (symbol==3) {
Result=num1 + "*" + num2 + "=" + (num1 * num2);
}
If (symbol==4) {
Result=num1 + "/" + num2 + "=" + (num1/num2);
}
//assignment result
Var result_dom=document. GetElementById (" result ");
Result_dom. The innerText=the result;

}

</script>

CodePudding user response:

refer to the second floor "the other shore flower reply:
& lt; Div>

Input operator:





Result: & lt; Span id="result" & gt;




<script>
The function calculate () {
//get operand 1
Var num1=parseFloat (document. GetElementById (" num1 "). The value).
//get operator
Var symbol=document. GetElementById (" symbol "). The value;
//get operand 2
Var num2=parseFloat (document. GetElementById (" num2 "). The value).

Operations//
Var result;
If (symbol==1) {
Result=num1 + + num2 + "=" + "+" (num1 + num2);
}
If (symbol==2) {
Result=num1 + "-" + num2 + "=" + (num1 - num2);
}
If (symbol==3) {
Result=num1 + "*" + num2 + "=" + (num1 * num2);
}
If (symbol==4) {
Result=num1 + "/" + num2 + "=" + (num1/num2);
}
//assignment result
Var result_dom=document. GetElementById (" result ");
Result_dom. The innerText=the result;

}

</script>
thank you bosses!
  • Related