請大神們幫我瞧瞧哪兒錯了以至于運行沒有反應(yīng),謝謝!
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? var txt1,txt2,fruit,select;
? ? txt1=document.getElementById("txt1").value;
? ? txt2=document.getElementById("txt2").value;
? ? select=document.getElementById("select").value;
? ? switch(select){
? ? ? ? case "+":
? ? ? ? ? ? fruit=parselnt(txt1)+parselnt(txt2);
? ? ? ? ? ? break;
? ? ? ? case "-":
? ? ? ? ? ? fruit=parselnt(txt1)-parselnt(txt2);
? ? ? ? ? ? break;
? ? ? ? case "*":
? ? ? ? ? ? fruit=parselnt(txt1)*parselnt(txt2);
? ? ? ? ? ? break;
? ? ? ? default:
? ? ? ? ? ? fruit=parselnt(txt1)/parselnt(txt2);
? ? }
? ? document.getElementById("fruit").value=fruit;?
? ?}
? </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>
2016-07-21
parselnt應(yīng)該寫成“”parseInt“”是大寫的i,不是l
2016-07-24
2016-07-22
這個就正確了,原來的錯誤原因:parsetInt的大寫的i寫成了小寫的l;變量名不能和ID一樣。
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? var a,b,num,c;
? ? a=document.getElementById("txt1").value;
? ? b=document.getElementById("txt2").value;
? ? c=document.getElementById("select").value;
? ? switch(c){
? ? ? ? case "+":
? ? ? ? ? ? num=parseInt(a)+parseInt(b);
? ? ? ? ? ? break;
? ? ? ? case "-":
? ? ? ? ? ? num=parseInt(a)-parseInt(b);
? ? ? ? ? ? break;
? ? ? ? case "*":
? ? ? ? ? ? num=parseInt(a)*parseInt(b);
? ? ? ? ? ? break;
? ? ? ? default:
? ? ? ? ? ? num=parseInt(a)/parseInt(b);
? ? }
? ? document.getElementById("fruit").value=num;?
? ?}
? </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>
2016-07-22
你的變量命名有問題,最后的輸出fruit可以換個變量名字試試,比如num輸出可以這樣寫:
同時,你的switch里面的變量都要改正
2016-07-22
我擦,我都測試過了居然不是最佳答案,心碎呀...
2016-07-21
fruit改成result
2016-07-21
parseInt才對你現(xiàn)在寫錯了