請各位幫我看看,不是懶真找不出來了
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title>?
? <script type="text/javascript">
?? function count(){???
??? var x1=document.getElementById("txt1").value;
??? var x2=document.getElementById("txt2").value;
??? var temp=document.getElementById("select").value;
??? var d="" ;
??? switch(temp) {
??????? case "+":
??????????? d= parseFloat(x1) + parseFloat(x2);
??????????? break;
??????? case "-":
??????????? d= parseFloat(x1) - parseFloat(x2);
??????????? break;
??????? case "*":
??????????? d= parseFloat(x1) * parseFloat(x2);
??????????? break;
??????? default:
??????????? d= parseFloat(x1) / parseFloat(x2);
??????????? break;
??? }
document.getElementById("fruit").value=d;
}
? </script>
?</head>
?<body>
?? 計數(shù)器:<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ù),得到結果-->
?? <input type='text' id='fruit' />??
?</body>
?</body>
</html>
2016-07-24
var x1?
case“/”不要跟defult連在一起的,去掉一個
document.getElementById("fruit").value=d 你后面應該是中文的;要改成英文的;