是if語句問題么?運行不起來~
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title>?
? <script type="text/javascript">
?? function count(){
????? a=parseFloat(document.getElementById("text1").value);
????? b=parseFloat(document.getElementById("text2").value);
????? c=document.getElementById("select").value;
??? //獲取第一個輸入框的值
?//獲取第二個輸入框的值
?//獲取選擇框的值
?//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
??? if(c=='+')
??? {cc=a+b;}
??? else if(c=='-')
??? {cc=a-c;}
??? else if(c=='*')
??? {cc=a*b}
??? else
??? {cc=a/b}
???
??? //設置結果輸入框的值
???? document.getElementById("fruit").value=cc;
?? }
? </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()"/> <!--通過 = 按鈕來調用創建的函數,得到結果-->
?? <input type='text' id='fruit'? />??
?</body>
</html>
2015-12-07
<!DOCTYPE?html> <html> <head> ????<title>?事件</title> ????<script?type="text/javascript"> ????function?count()?{ ????????var?a?=?parseFloat(document.getElementById("txt1").value); ????????var?b?=?parseFloat(document.getElementById("txt2").value); ????????var?c?=?document.getElementById("select").value; ????????var?d; ????????//獲取第一個輸入框的值 ????????//獲取第二個輸入框的值 ????????//獲取選擇框的值 ????????//獲取通過下拉框來選擇的值來改變加減乘除的運算法則 ????????if?(c?==?'+')?{ ?????????????d=?a?+?b; ????????}?else?if?(c?==?'-')?{ ?????????????d=?a?-?c; ????????}?else?if?(c?==?'*')?{ ????????????d?=?a?*?b; ????????}?else?{ ?????????????d=?a?/?b; ????????} ????????//設置結果輸入框的值 ????????document.getElementById("fruit").value?= ????????????d; ????} ????</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()"?/> ????<!--通過?=?按鈕來調用創建的函數,得到結果--> ????<input?type='text'?id='fruit'?/> </body> </html>有些你寫錯了 比如 獲取 id 的ID值。 還有不能用var做變量值。
2015-12-07
你是傳說中的慕男神么?天天給人解答問題哈~
問題1,a b c d 前面不加var也可以運行,那么加與不加的區別在哪?
問題2,你的所有運算都有空格,比如c = a + b,沒有也可以運行,那么目的何在?
問題3,JS不識別單引號雙引號哈?