<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
var p,q,s,sum;
p=document.getElementById("txt1").value;
q=document.getElementById("txt2").value;
s=document.getElementById("select").value;
sum;
function count(){
switch(s)
{
case"+":sum=parseInt(p)+parseInt(q);
break;
case"-":sum=parseInt(p)-parseInt(q);
break;
case"*":sum=parseInt(p)*parseInt(q);
break;
case"/":sum=parseInt(p)/parseInt(q);
break;
}
}
document.getElementById("fruit").value=sum;
</script>
<style type=text/css>
#txt2{
width:80px;
}
#txt1{
width:80px;
}
#fruit{
width:120px;
}
</style>
</head>
<body>
<input type='text' id='txt1' />
<select id='select'>
<option value='+'>+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select><br/><br/>
<input type='text' id='txt2' />
<input type='button' value=' = ' onclick="count()"/> <br/><br/><!--通过 = 按钮来调用创建的函数,得到结果-->
<input type='text' id='fruit' />
</body>
</html>
__innocence
李晓健
蜂之谷
相关分类