腫么搞得一點反應都沒有????
<!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 x=" ";
? ? ? ?switch(c){
? ? ? ? ? ?case '+':xt=parseInt(a)+parseInt(b);break;
? ? ? ? ? ?case '-':x=parseInt(a)-parseInt(b);break;
? ? ? ? ? ?case '*':x=parseInt(a)*parseInt(b);break;
? ? ? ? ? ?case '/':x=parseInt(a)/parseInt(b);break;
? ? ? ?}
? ? ? ?document.getElementById("fruit").value=x;
? ?}
? </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>
求幫忙看看到底哪里錯啦啊。。
2014-11-21
第一,你仔細看一下,你對a,b賦值時getElementById后面取的是不是對應input的id?你取的是它們的type,當然不會有反應。
第二,你case '+':后面的x寫成了xt