<script>
var s1 = "";
var s2 = "";
var s3 = "";
var s4 = "";
var s5 = "";//定义变量
function view(val){
var a = document.getElementById(val);//定义变量a,把val值给变量a
s1 = a.innerHTML;//将表格内的变量a赋值给s1
if(s1=="+" || s1=="-" || s1=="*" || s1=="/"){
s3 = s1;
s1 = "";
}
if(s3=="+" || s3=="-" || s3=="*" || s3=="/"){
add2(s1);
}
if(s3==""){
add1(s1);
}
}
function add1(s1){
s2 = s2 + s1;
show();
}
function add2(s1){
s4 = s4 + s1;
show();
}
function cal(){
switch(s3){
case "+":{
s5 = (String)((parseFloat(s2)+parseFloat(s4)).toFixed(2));//parseFloat解析字符串,返回一个浮点数,固定2位小数,
result.innerHTML = s5;
break;
}
case "-":{
s5 = (String)((parseFloat(s2)-parseFloat(s4)).toFixed(2)); result.innerHTML = s5;
break;
}
case "*":{
s5 = (String)((parseFloat(s2)*parseFloat(s4)).toFixed(2)); result.innerHTML = s5;
break;
}
case "/":{
s5 = (String)((parseFloat(s2)/parseFloat(s4)).toFixed(2)); result.innerHTML = s5;
break;
}
}
}
function show(){
var result=document.getElementById("result");
result.innerHTML = s2+s3+s4;
}
</script>
漂流風車
漂流風車
漂流風車
相关分类