<!DOCTYPE?html>
<html>
<head>
????<title>?事件</title>
????<script?type="text/javascript">
???function?count(){???
???????var?n1?=?parseInt(?document.getElementById("text1").value);??
???????var?n2?=?parseInt(?document.getElementById("text2").value);????
???????var?ff?=?document.getElementById("select").value;
???????var?rs?=?"";????
???????switch?(ff)?{
???????????case?'+':
???????????????rs?=?n1?+?n2;
???????????????break;
???????????case?'-':
???????????????rs?=?n1?-?n2;
???????????????break;
???????????case?'*':
???????????????rs?=?n1?*?n2;
???????????????break;
???????????case?'/':
???????????????rs?=?n1?/?n2;
???????????????break;
???????}
????//設置結果輸入框的值
???????document.getElementById('fruit').value?=?rs;
???}
????</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()"/>?<!--通過?=?按鈕來調用創(chuàng)建的函數(shù),得到結果-->
????<input?type='text'?id='fruit'?/>
</body>
</html>
2016-04-07
id為txt1 txt2你寫錯了,建議以后復制
2016-03-28
定義變量rs有問題。
就夠了