慕粉1010084486
2018-08-01 10:31
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=utf-8">
<title>计算器</title>
//计算函数
<script type="text/javascript">
function count(){
var n1=document.getElementById("num1").value;
var n2=document.getElementById("num2").value;
var n=document.getElementById("select").value;
var count="";
swicth(n){
case "+":
count=parseFloat(n1)+parseFloat(n2);
break;
case "-":
count=parseFloat(n1)-parseFloat(n2);
break;
case "*":
count=parseFloat(n1)*parseFloat(n2);
break;
case "/":
count=parseFloat(n1)/parseFloat(n2);
break;
}
document.getElementById("fruit").value=count;
}
</script>
</head>
<body>
<form>
//界面显示
<input type="text" id="num1" />
<select id="select">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="num2" />
<input type="button" value="=" onclick="count()" /><br/>
<input type="text" id="fruit" />
</form>
</body>
</html>
swicth写错了 是switch
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题