無法顯示計算結果
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title>??
? <script type="text/javascript">
? ?function count(){
? ? ? ?
? ? ? ?var t1,t2,single;
? ? //獲取第一個輸入框的值
? ? t1=document.getElementById("txt1").value;
//獲取第二個輸入框的值
? ? t1=document.getElementById("txt2").value;
//獲取選擇框的值
single=document.getElementById("select").value;
//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
switch(select)
{
? ? case "+":
? ? document.getElementById("fruit").value=paresFloat(t1)+paresFloat(t2);
? ? break;
? ? case "-":
? ? document.getElementById("fruit").value=paresFloat(t1)-paresFloat(t2);
? ? break;
? ? case "*":
? ? document.getElementById("fruit").value=paresFloat(t1)*paresFloat(t2);
? ? break;
? ? case "/":
? ? document.getElementById("fruit").value=paresFloat(t1)/paresFloat(t2);
? ? break;
? ? default:
? ? document.write("ERROR");
}
? ? //設置結果輸入框的值?
??
? ?}
? ?
? </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=' = ' onclik="count()"/> <!--通過 = 按鈕來調用創建的函數,得到結果-->?
? ?<input type='text' id='fruit' />? ?
?</body>
</html>
2019-04-07
親,你的bug我幫你修改了,請復制粘貼代碼到編輯器查看。
1、單詞拼錯,應該是給t2賦值,你給兩個t1賦值了
2、還是單詞拼錯,應該是parseFloat,你拼成了paresFloat
3、變量判斷錯誤,應為switch (single),而不是switch (select)