能幫我看下哪里錯了嗎,點擊按鈕不顯示結(jié)果
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? var a=document.getElementById(txt1).value;
? var b=document.getElementById(txt2).value;
? var op=document.getElementById(select).value;
? var result;
? switch(op){
? ? ? case "+":?
? ? ? ? ? result=parseInt(a)+parseInt(b);
? ? ? ? ? break;
? ? ? case "-":?
? ? ? ? ? result=parseInt(a)-parseInt(b);
? ? ? ? ? break;
? ? ? case "*":?
? ? ? ? ? result=parseInt(a)*parseInt(b);
? ? ? ? ? break;
? ? ? default:?
? ? ? result=parseInt(a)/parseInt(b); ? ?
? }
? 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()"/> <!--通過 = 按鈕來調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->?
? ?<input type='text' id='fruit' /> ??
?</body>
</html>
2015-08-10
(⊙﹏⊙)b···大哥你用document.getElementById() ··時···里面請加雙引號··比如:document.getElementById("fruit")