哪里錯了 ,怎么運行不出來、、
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? ?var c=""; ?
? ? //獲取第一個輸入框的值
? ? var a = document.getElementById('txt1').value;
//獲取第二個輸入框的值
var b = document.getElementById("txt2").value;
//獲取選擇框的值
var d = document.getElementById("select").value;
//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
?switch(d){
?case "+": c=parseInt(a) + parseInt(b); break;
?case "-": c=parseInt(a) - parseInt(b); break;
?case "*": c=parseInt(a) * parseInt(b); break;
?case "/": c=parseInt(a) / parseInt(b); break;
?}
? ? //設置結果輸入框的值?
? ? document.getElementById("fruit")= c;
? ? document.write(a);
? ?}
? </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>
2017-02-13
你的代碼有三處問題:
? var d = document.getElementById("select").value;這句后面的冒號應該為英文格式下的輸入,你的是中文下的輸入
document.getElementById("fruit")= c; 這句少個.value,正確的是document.getElementById("fruit").value= c
注釋掉document.write(a);
改了這三處,代碼就會按要求運行。
2017-02-08
把document.write(a);去掉