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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

問題在哪里呢 怎么沒有反應(yīng)啊 計(jì)算不出結(jié)果

問題在哪里呢 怎么沒有反應(yīng)啊 計(jì)算不出結(jié)果

SophieRabbit 2016-06-02 14:17:15
<!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=" ";? ? //獲取第一個(gè)輸入框的值 //獲取第二個(gè)輸入框的值 //獲取選擇框的值 //獲取通過下拉框來選擇的值來改變加減乘除的運(yùn)算法則? ? switch(select){? ? ? ? case"+":? ? ? ? ? ? result=parseInt(txt1)+parseInt(txt2);? ? ? ? ? ? break;? ? ? ? case"-":? ? ? ? ? ? result=parseInt(txt1)-parseInt(txt2);? ? ? ? ? ? break;? ? ? ? case"*":? ? ? ? ? ? result=parseInt(txt1)*parseInt(txt2);? ? ? ? ? ? break;? ? ? ? case"/":? ? ? ? ? ? result=parseInt(txt1)/parseInt(txt2);? ? ? ? ? ? break;? ? //設(shè)置結(jié)果輸入框的值?? ? ? ? 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>
查看完整描述

2 回答

已采納
?
丶包菜

TA貢獻(xiàn)158條經(jīng)驗(yàn) 獲得超233個(gè)贊

1,建議把JavaScript? 寫后面,避免以后獲取不到值得問題。

2,那些id=""??? type=""?? 建議是要用雙引號(hào)。

3,? document.getElementById("fruit").value=result;??? 寫在了 switch 語句里面,注意

<!DOCTYPE html>

<html>

?<head>

? <title> 事件</title> ?
? <meta charset="utf-8">
?
?</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"/>? ?
? ?
? ?
?? <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=parseInt(txt1)+parseInt(txt2);

??????????? break;

??????? case"-":

??????????? result=parseInt(txt1)-parseInt(txt2);

??????????? break;

??????? case"*":

??????????? result=parseInt(txt1)*parseInt(txt2);

??????????? break;

??????? case"/":

??????????? result=parseInt(txt1)/parseInt(txt2);

??????????? break;??
??? }
??? document.getElementById("fruit").value=result;

?? }?
? </script>
?</body>
?</html>

望采納。

查看完整回答
反對(duì) 回復(fù) 2016-06-02
?
Caballarii

TA貢獻(xiàn)1123條經(jīng)驗(yàn) 獲得超629個(gè)贊

document.getElementById("fruit").value=result;要寫在switch語句塊之外才能顯示結(jié)果啊

查看完整回答
1 反對(duì) 回復(fù) 2016-06-02
  • 2 回答
  • 0 關(guān)注
  • 1445 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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