各位大神能幫我找下錯誤嗎?還是無法運行
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
?? function count(){
????? ?
??? //獲取第一個輸入框的值
??? var shu1 = parseInt(document.getElementById('txt1').value);
?? ?
?? ?//獲取第二個輸入框的值
?? ?var shu2 = parseInt(document.getElementById('txt2').value);
?? ?
?? ?//獲取選擇框的值
?? ?var fu = document.getElementById('select').value;
?? ?
?? ?//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
?? ?var final ='';
?? ?swich (fu){
?? ??? ?
?? ??? case '+' :
?? ??? fianl = shu1 + shu2;
?? ??? break;
?? ??? case '-' :
?? ???? final = shu1 - shu2;
?? ???? break;
?? ???? case '*' :
?? ???? fianl = shu1 * shu2;
?? ???? break;
?? ???? case '/' :
?? ??? final = shu1 / shu2;
?? ??? break;
?? ?}
?? ?
?? ?
??? //設置結(jié)果輸入框的值
??? document.getElementById("fruit").value = final;
?? ?
?? }
? </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()"/> <!--通過 = 按鈕來調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->
?? <input type='text' id='fruit' />? ?
?</body>
</html>
2018-11-01
這3個位置拼寫錯誤,switch , final , final。。
這種拼寫錯誤一定要注意啊,找錯的話請用本地瀏覽器來查,很容易發(fā)現(xiàn)的
2018-10-30
var final =''
這里拼錯了,應該是
var final=""
英文的雙引號少了一半
2018-10-29
switch 函數(shù)里面 + 和* 變量名錯了