PHP Exercises-Four calculator
I. Focus: The practice of JS DOM elements
Two. The code is as follows:
<! DOCTYPE html>
<meta charset= "UTF-8"/>
<title> Calculator </title >
<script type= "text/javascript";
function count () {
var d = "";
var A=document.getelementbyid ("Txt1"). Value;
//a value
var b=document.getelementbyid ("Txt2"). Value;
The value of B is
var C=document.getelementbyid ("select"). Value;
The value of the operation symbol
Switch (c)
{
Case "+":
//d = a + B; to an integer
D = parseint (a) +parseint (b);
Break
Case "-":
D = A-B;
Break
Case "":
D = a b;
Break
Default:
D = A/b;
}
document.getElementById ("fruit"). Value = D;
}
</script>
<body>
Four calculator: <input type= ' text ' id= ' txt1 '/>
<select id= ' SELECT ' >
<option value= ' + ' >+</option>
<option value= "-" >-</option>
<option value= "" ></option>
<option value= "/" >/</option>
</select>
<input type= ' text ' id= ' txt2 '/>
<input type= ' button ' value= ' = ' onclick= ' count () '/>
<input type= ' text ' id= ' fruit '/>
</body>
Three. Page output:
PHP Exercises-Four Calculator