腫么搞得一點(diǎn)反應(yīng)都沒(méi)有?。浚?/h1>
<!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()"/> <!--通過(guò) = 按鈕來(lái)調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->?
? ?<input type='text' id='fruit' /> ??
?</body>
</html>
求幫忙看看到底哪里錯(cuò)啦啊。。
<!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()"/> <!--通過(guò) = 按鈕來(lái)調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->?
? ?<input type='text' id='fruit' /> ??
?</body>
</html>
求幫忙看看到底哪里錯(cuò)啦啊。。
2014-11-21
第一,你仔細(xì)看一下,你對(duì)a,b賦值時(shí)getElementById后面取的是不是對(duì)應(yīng)input的id?你取的是它們的type,當(dāng)然不會(huì)有反應(yīng)。
第二,你case '+':后面的x寫(xiě)成了xt