請幫我看看問題出在哪,結果計算是錯的
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? ? ?var a=document.getElementById("txt1").value;
? ? ? ? var b=document.getElementById("txt2").value;
? ? ? ? ?var c=document.getElementById("select").value;
? ? ? ? ?var re;
??
? ? ? ? ?if(c=="+")
? ? ? ? ?{re=parseInt(a)+parseInt(b);}
? ? ? ? ?else if(c=="-")
? ? ? ? ?{re=a-b;}
? ? ? ? ?else if(c=="*")
? ? ? ? ?{re=a*b;}
? ? ? ? ?else (c=="/")
? ? ? ? ?{re=a/b;}
? ? ? ? ? document.getElementById("fruit").value=re;
?
? ??
? ?}
? </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)建的函數,得到結果-->?
? ?<input type='text' id='fruit' /> ??
?</body>
</html>
2017-11-02
else后面的去掉就是了··
2017-11-02
已找到