我想知道我的代碼到底哪里錯(cuò)了,為什么點(diǎn)擊等于號(hào)不等得出結(jié)果
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? var a=document.getElementById("text1").value;
? ? //獲取第一個(gè)選擇框的內(nèi)容
? ? var b=document.getElementById("text2").value;
? ? //獲取第二個(gè)選擇框的內(nèi)容
? ? var c=document.getElementById("select").value;
? ? var result;
? ? //獲取選擇框的內(nèi)容
? ? 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=' = ' /> <!--通過(guò) = 按鈕來(lái)調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->?
? ?<input type='text' id='fruit' /> ??
?</body>
</html>
2017-03-30
id錯(cuò)了 ?下面是txt1,上面是text1