我想知道我的代碼到底哪里錯了,為什么點擊等于號不等得出結果
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? var a=document.getElementById("text1").value;
? ? //獲取第一個選擇框的內容
? ? var b=document.getElementById("text2").value;
? ? //獲取第二個選擇框的內容
? ? var c=document.getElementById("select").value;
? ? var result;
? ? //獲取選擇框的內容
? ? switch(c)
? ? {
? ? ? ? case '+':
? ? ? ? ? ? result=parseInt(a)+parseInt(b);
? ? ? ? ? ? break;
? ? ? ? case '-':
? ? ? ? ? ? result=parseInt(a)-parseInt(b);
? ? ? ? ? ? break;
? ? ? ? case '*':
? ? ? ? ? ? result=parseInt(a)*parseInt(b);
? ? ? ? ? ? break;
? ? ? ? case '/':
? ? ? ? ? ? result=parseInt(a)/parseInt(b);
? ? ? ? ? ? break;
? ? ? ? default;
? ? }
? ?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=' = ' /> <!--通過 = 按鈕來調用創建的函數,得到結果-->?
? ?<input type='text' id='fruit' /> ??
?</body>
</html>
2017-03-30
id錯了 ?下面是txt1,上面是text1