第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

6-11編程練習(xí)為什么我的計算器減法除法乘法都正常,唯獨加法2+3會等于23呢?

<!DOCTYPE html>

<html>

?<head>

? <title> 事件</title> ?

? <script type="text/javascript">

? ?function count(){

? ? var txt1=document.getElementById("txt1").value;

var txt2=document.getElementById("txt2").value;

var select=document.getElementById("select").value;

? ? var result;

switch(select){

? ? ?case "+":

? ? ? ? ?result=txt1+txt2;

? ? ? ? ?break;

? ? ?case "-":

? ? ? ? ?result=txt1-txt2;

? ? ? ? ?break;

? ? ?case "*":

? ? ? ? ?result=txt1*txt2;

? ? ? ? ?break;

? ? ?case "/":

? ? ? ? ?if(txt2==0){

? ? ? ? ? ? ?alert("0不能做被除數(shù)!")

? ? ? ? ?}

? ? ? ? ?result=txt1/txt2;

? ? ? ? ?break;

}

? ? 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>


正在回答

1 回答

你的加號,在運算中的作用是作為 ?連接,而不是加法,



0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕移動9485495 回復(fù) __呵呵噠_ 提問者

你用input得到的數(shù)字,實際上是字符串,要用方法轉(zhuǎn)換成整數(shù)或者浮點數(shù)才能進(jìn)行算法運算比如你在var txt2=document.getElementById("txt2").value; var select=document.getElementById("select").value; txt1=parseInt(txt1); txt2=parseInt(txt2);/*轉(zhuǎn)化成整數(shù)*/ var result;這樣就可以運算了
2016-09-27 回復(fù) 有任何疑惑可以回復(fù)我~
#2

__呵呵噠_ 提問者

非常感謝!
2016-09-27 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

6-11編程練習(xí)為什么我的計算器減法除法乘法都正常,唯獨加法2+3會等于23呢?

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號