點擊“=”沒反應,不知道問題出在那里。
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? var num1 = document.getElementById("txt1").value
? ? var num2 = document.getElementById("txt2").value
? ? var select = document.getElementById("select").value
? ? var result="";
? ? switch(select){
? ? ? ? case "+":
? ? ? ? ? ? result=parseFolat(num1)+parseFolat(num2);
? ? ? ? ? ? break;
? ? ? ? case "-":
? ? ? ? ? ? result=parseFolat(num1)-parseFolat(num2);
? ? ? ? ? ? break;
? ? ? ? case "*":
? ? ? ? ? ? result=parseFolat(num1)*parseFolat(num2);
? ? ? ? ? ? break;
? ? ? ? default "/":
? ? ? ? ? ? result=parseFolat(num1)/parseFolat(num2);
? ? }
? ? document.getElementById("fruit").value=result;
? ?}
? </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' /> ??
?</body>
</html>
2016-09-01
【default "/":】改成【default:】
【parseFolat】改成【parseInt】
2016-09-01
兩個地方寫錯了:
所有的parseFolat都寫錯了, 應該是parseFloat , o和l顛倒
switch語句里面?default "/": 錯了 ,default是沒有值的,所以直接寫 ?default: 就行了 ?把"/"去掉