<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
var t1=parseInt(document.getElementById("txt1").value);
var t2=parseInt(document.getElementById("txt2").value);
var t3=document.getElementById("select");
var jieguo;
function jisuan()
{
if(t3=="+")
{
jieguo=t1+t2;
}
else if(t3=="-")
{
jieguo=t1-t2;
}
else if(t3=="*")
{
jieguo=t1*t2;
}
else
{
jieguo=t1/t2;
}
document.getElementById("fruit").value=jieguo;
}
</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="jisuan()" />
<input type='text' id='fruit' />
</body>
</html>
var t1=parseInt(document.getElementById("txt1").value);
var t2=parseInt(document.getElementById("txt2").value);
var t3=document.getElementById("select");
var jieguo;
这几个变量定义要放到方法里面去,因为方法内无法调用方法外的变量