點(diǎn)等號(hào)沒有反應(yīng),求人幫忙給我查下錯(cuò),自己確實(shí)查不出來了
<!DOCTYPE?html> <html> ?<head> ??<title>?事件</title>?? ??<script?type="text/javascript"> ???function?count(){ ????//獲取第一個(gè)輸入框的值 ????var?txt1?=?parseInt(document.getElementById("txt1").value); //獲取第二個(gè)輸入框的值 var?txt2?=?parseInt(document.getElementById("txt2").value); //獲取選擇框的值 var?opt?=?document.getElementById("select").value; //獲取通過下拉框來選擇的值來改變加減乘除的運(yùn)算法則 var?result; switch(opt){ ????case?"+": ????????result?=?txt1)+?txt2); ????????break; ????case?"-": ????????result?=?txt1)-?txt2); ????????break; ????case?"*": ????????result?=?txt1)*?txt2); ????????break; ????case?"/": ????????result?=?txt1)/?txt2); ????????break; ???? default: ???? } ???? //設(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> </html>
要瘋了,不知道哪里錯(cuò)了?
2017-03-18
?result?=?txt1)+?txt2); ?改成:result = txt1- txt2;
2017-03-21
<!DOCTYPE html>
<html>
?<head>
? <meta charset="utf-8">
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? ? //獲取第一個(gè)輸入框的值
? ? ? ? var num1=parseInt(document.getElementById("txt1").value);
? ? ? //獲取第二個(gè)輸入框的值
? ? ? ? var num2=parseInt(document.getElementById("txt2").value);
? ? ? //獲取選擇框的值
? ? ? ? var operator=document.getElementById("select").value;
? ? ? //獲取通過下拉框來選擇的值來改變加減乘除的運(yùn)算法則
? ? ? var finalNum;
? ? ? ? switch (operator) {
? ? ? ? ? case "-":
? ? ? ? ? ? finalNum=num1-num2;
? ? ? ? ? ? break;
? ? ? ? ? case "*":
? ? ? ? ? ? finalNum=num1*num2;
? ? ? ? ? ? break;
? ? ? ? ? case "/":
? ? ? ? ? ? finalNum=num1/num2;
? ? ? ? ? ? break; ??
? ? ? ? ? default:
? ? ? ? ? ? finalNum=num1+num2;
? ? ? ? ? ? break;
? ? ? ? };
? ? ? //設(shè)置結(jié)果輸入框的值?
? ? ? ? document.getElementById("fruit").value=finalNum;
? ?}
? </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>
2017-03-19
謝謝,Thx
2017-03-19
你試試吧
2017-03-19
2017-03-18
....黑色背景太傷了,藍(lán)色的括號(hào)完全看不見。。。
2017-03-18
還是不行。。。
2017-03-18
啊,我知道了,有個(gè)var寫錯(cuò)了.......