php练习
php练习-四则计算器一.重点:js的dom元素的练习
二.代码如下:
计算器
function count(){
var d = "";
var a=document.getElementById("txt1").value;
//a的值
var b=document.getElementById("txt2").value;
//b的值
var c=document.getElementById("select").value;
//运算符号的值
switch(c)
{
case "+":
//d = a + b;转为整数
d = parseInt(a)+parseInt(b);
break;
case "-":
d = a-b;
break;
case "":
d = ab;
break;
default:
d = a/b;
}
document.getElementById("fruit").value = d;
}
四则计算器:
+
-
/
三.页面输出:
http://i2.运维网.com/images/blog/201807/01/23c5c6b744e7e0ea5cf71595466e229d.jpg
页:
[1]