看了一個小時 都看不出問題啊
?function count(){
????
????? var var1;
????? var var2;
?????? var1 = parseInt(document.getElementById("txt1").value);
?????? var2 = parseInt(document.getElementById("txt2").value);
?????? sel = document.getElementById("select").value;
?????? var x="";
??????
?????? switch(sel)
?????? {
?????????? case '+': x=var1 + var2; break;
?????????? case '-': x=var1 - var2; break;
?????????? case '*': x=var1 * var2; break;
?????????? case '/': x=var1 / var2? break;
??????????
?????? }
?????
?????? document.getElementById("fruit").value=x;
??????
??? //獲取第一個輸入框的值
?//獲取第二個輸入框的值
?//獲取選擇框的值
?//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
??? //設置結果輸入框的值
???
?? }
? </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()"/> <!--通過 = 按鈕來調用創建的函數,得到結果-->
?? <input type='text' id='fruit' />??
2018-02-02
你代碼中的括號用的是中文狀態的,(),換成()。例如這里:var1 = parseInt(document.getElementById("txt1").value);
?????? var2 = parseInt(document.getElementById("txt2").value);
2018-02-02
剛才截圖出現了問題 那個第四個case后面 有分號? 我截圖時截沒了
2018-02-02
我點擊等于號 沒反應? 然后我在function里加了一個alert函數 也沒有警告 是怎么回事啊