<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
function count(){
//获取第一个输入框的值
var value1=document.getElementById("txt1").value.parseInt();
//获取第二个输入框的值
var value2=document.getElementById("txt2").value.parseInt();
var result=" ";
//获取选择框的值
switch(document.getElementById("select").value)
{
case '+':
result=value1+value2;
break;
case '-':
result=value1-value2;
break;
case '*':
result=value1*value2;
break;
case '/':
result=value1/value2;
}
document.getElementById("fruit").value=result;
}
</script>
</head>
<body>
<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='fruit' />
</body>
</html>
parseInt()用错了吧,应该是parseInt(document.getElementById("txt1").value)