課程
/前端開發(fā)
/JavaScript
/JavaScript進(jìn)階篇
請(qǐng)幫忙看看
2020-09-06
源自:JavaScript進(jìn)階篇 6-11
正在回答
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title>??
? <script type="text/javascript">
? ?function count(){
? ? ? ?
? ? //獲取第一個(gè)輸入框的值
//獲取第二個(gè)輸入框的值
//獲取選擇框的值
//獲取通過下拉框來(lái)選擇的值來(lái)改變加減乘除的運(yùn)算法則
? ? //設(shè)置結(jié)果輸入框的值?
? ? var a = document.getElementById('txt1').value;
? ? var b = document.getElementById('txt2').value;
? ? var c = document.getElementById('select').value;
? ? var d = a
? ? switch(c){
? ? ? ? case '+': document.getElementById('fruit').value= parseInt(a)+parseInt(b);
? ? ? ? break;
? ? ? ? case '-': document.getElementById('fruit').value = a-parseInt(b);
? ? ? ? case '*': document.getElementById('fruit').value = a*parseInt(b);
? ? ? ? case '/': document.getElementById('fruit').value = a/parseInt(b);
? ? ? ? default: document.getElementById('fruit').value = ('計(jì)算錯(cuò)誤');
? ? }
? ??
? ?}
? </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()"/> <!--通過 = 按鈕來(lái)調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->?
? ?<input type='text' id='fruit'/>? ?
?</body>
</html>
還有這個(gè)+,-,*,/,是字符串,你這里case加上'',case '+':
能不能把整個(gè)發(fā)出來(lái)
舉報(bào)
本課程從如何插入JS代碼開始,帶您進(jìn)入網(wǎng)頁(yè)動(dòng)態(tài)交互世界
2 回答數(shù)字和字符串拼接是什么
1 回答為什么加法是字符串的拼接?
2 回答字符串減字符串也會(huì)轉(zhuǎn)化為數(shù)字???
2 回答concat還可以連接字符串嗎?我寫了兩個(gè)字符串也連接上了
1 回答為什么加法會(huì)被當(dāng)成連接字符串處理呢?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2020-11-17
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title>??
? <script type="text/javascript">
? ?function count(){
? ? ? ?
? ? //獲取第一個(gè)輸入框的值
//獲取第二個(gè)輸入框的值
//獲取選擇框的值
//獲取通過下拉框來(lái)選擇的值來(lái)改變加減乘除的運(yùn)算法則
? ? //設(shè)置結(jié)果輸入框的值?
? ? var a = document.getElementById('txt1').value;
? ? var b = document.getElementById('txt2').value;
? ? var c = document.getElementById('select').value;
? ? var d = a
? ? switch(c){
? ? ? ? case '+': document.getElementById('fruit').value= parseInt(a)+parseInt(b);
? ? ? ? break;
? ? ? ? case '-': document.getElementById('fruit').value = a-parseInt(b);
? ? ? ? break;
? ? ? ? case '*': document.getElementById('fruit').value = a*parseInt(b);
? ? ? ? break;
? ? ? ? case '/': document.getElementById('fruit').value = a/parseInt(b);
? ? ? ? break;
? ? ? ? default: document.getElementById('fruit').value = ('計(jì)算錯(cuò)誤');
? ? ? ? break;
? ? }
? ??
? ?}
? </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()"/> <!--通過 = 按鈕來(lái)調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->?
? ?<input type='text' id='fruit'/>? ?
?</body>
</html>
2020-09-07
還有這個(gè)+,-,*,/,是字符串,你這里case加上'',case '+':
2020-09-07
能不能把整個(gè)發(fā)出來(lái)