编程练习6-11
<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
function count(){
//获取输入框1的值
var txt1=document.getElementById("txt1").value;
//获取输入框2的值
var txt2=document.getElementById("txt2").value;
//获取下拉框的值
var sele=document.getElementById("select").value;
//获取结果输出框
var result=document.getElementById("fruit");
//判断下拉框选项,求值
switch(sele){
case '+' :
result.value=parseInt(txt1)+parseInt(txt2);
break;
case '-' :
result.value=txt1-txt2;
break;
case '*' :
result.value=txt1*txt2;
break;
case '/' :
result.value=txt1/txt2;
break;
}
}
</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='fruit' />
<input type="reset" value="清除">
</form>
</body>
</html>