<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>practice</title>
<script>
function count(){
var aa=document.getElementById("txt1");
var bb=document.getElementById("txt2");
var cc=document.getElementById("select");
var result=" ";
switch(cc){
case "+":result=parseFloat(aa)+parseFloat(bb);
break;
case "-":result=aa-bb;
break;
case "*":result=aa*bb;
break;
case "/":result=aa/bb;
break;
}
document.getElementById("txt3").value=result;
}
</script>
</head>
<body>
<form>
<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="txt3">
</form>
</body>
</html>
var aa=document.getElementById("txt1");
var bb=document.getElementById("txt2");
var cc=document.getElementById("select");
每个后面是要取它们的值才对,加行.value 改为:
var aa=document.getElementById("txt1").value ; var bb=document.getElementById("txt2").value ; var cc=document.getElementById("select").value ;
找到问题了
function count(){
var aa=document.getElementById("txt1");
var bb=document.getElementById("txt2");
var cc=document.getElementById("select");
后面不是取他的值 掉了.value