<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>练习写一个简单的计算器</title>
<script type="text/javascript">
function click(){
var a=document.getElementById("one").value;
var b=document.getElementById("two").value;
var Os=document.getElementById("selec").value;
var c="";
switch(Os){
case"+":
c=parseFloat(a)+parseFloat(b);
break;
case"-":
c=parseFloat(a)-parseFloat(b);
break;
case"*":
c=parseFloat(a)*parseFloat(b);
break;
case"/":
c=parseFloat(a)/parseFloat(b);
}
document.getElementById("three").value=c;
}
</script>
</head>
<body>
<input type="text" id="one" />
<select id="selec">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="two" />
<input type="button" value="=" onclick="click()" />
<input type="text" id="three" />
</body>
</html>
你那个点击事件好像没有触发 click()是 保留字 换成别的