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

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

我想知道這個用if else怎么做

我想知道這個用if else怎么做

正在回答

4 回答

<script type="text/javascript">
? function count(){
?? ??? //獲取第一個輸入框的值
? ?? ?var number1=document.getElementById("txt1").value;
?? ?//獲取第二個輸入框的值
??? var number2=document.getElementById("txt2").value;
?? ?//獲取選擇框的值
??? var option=document.getElementById("select").value;
?? ?//獲取通過下拉框來選擇的值來改變加減乘除的運(yùn)算法則
?? ?if(option=="+")
??????? sum=parseInt(number1)+parseInt(number2);
??? else
??????? if(option=="-")
??????????? sum=parseInt(number1)-parseInt(number2);
??????? else
??????????? if(option=="*")
??????????????? sum=parseInt(number1)*parseInt(number2);
??????????? else
??????????????? sum=parseInt(number1)/parseInt(number2);
?? ??? ??? ??? ?//設(shè)置結(jié)果輸入框的值
?? ?document.getElementById("fruit").value=sum;
?? ??? ??? ??? ?
? }
? </script>

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

cireay 提問者

為什么加了大括號就不行了呢?
2016-04-15 回復(fù) 有任何疑惑可以回復(fù)我~

function count() {

var txt1 = parseInt(document.getElementById('txt1').value); //獲取第一個輸入框的值

var txt2 = parseInt(document.getElementById('txt2').value); //獲取第二個輸入框的值

var sel = document.getElementById('select').value; //獲取選擇框的值

var result = '';

if(sel = '+') {

result = txt1 + txt2;

} else if(sel = '-') {

result = txt1 - txt2;

} else if(sel = '*'){

result = txt1 * txt2;

}

else{

result = txt1 / txt2;

}

document.getElementById('fruit').value = result;

}


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

山巔對弈

好像是有bug存在,但是我找不出來在哪,隱藏的大神改你們出招拯救世界了……
2017-04-21 回復(fù) 有任何疑惑可以回復(fù)我~

? ? ? ?if (select == "+")

? ? ? ?{

? ? ? ? sum = parseFloat(num1) + parseFloat(num2);

? ? ? ?}

? ? ? ?else if (select == "-")

? ? ? ?{

? ? ? ? sum = parseFloat(num1) - parseFloat(num2);

? ? ? ?}

? ? ? ?else if (select == "*")

? ? ? ?{

? ? ? ? sum = parseFloat(num1) * parseFloat(num2);

? ? ? ?}

? ? ? ?else if (select == "/")

? ? ? ?{

? ? ? ? sum = parseFloat(num1) / parseFloat(num2);

? ? ? ?}

? ? ? ?else

? ? ? ?{

? ? ? ? document.write("default!!");

? ? ? ?}


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

cireay 提問者

這個也不行呢
2016-04-15 回復(fù) 有任何疑惑可以回復(fù)我~

?

var txt1 ? = parseInt( document.getElementById('txt1').value);//獲取第一個輸入框的值

var txt2 ? = parseInt( document.getElementById('txt2').value);//獲取第二個輸入框的值

var select = document.getElementById('select').value;//獲取選擇框的值

var result = '';

if (select=="+")

{

result = txt1 + txt2;

break;}

else if(select=="-")

{result = txt1 - txt2;

break;}

else if(select=="*")

? ? ? ? ? ? ? ? {result = txt1 * txt2;

break;}

else

{result = txt1 / txt2;

break;} ?

?

? ? ? ? ?document.getElementById('fruit').value = result;//設(shè)置結(jié)果輸入框的值?

? ?}


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

cireay 提問者

這樣輸不出結(jié)果的 我試過了
2016-04-15 回復(fù) 有任何疑惑可以回復(fù)我~
#2

山巔對弈

break不能添加
2017-04-21 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

我想知道這個用if else怎么做

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

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

幫助反饋 APP下載

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

公眾號

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