問題在哪里 ????請各位路過的大神指點指點
<script type="text/javascript">
?? function count(){
var dy =document.getElementById("txt1").value;
var ds=document.getElementById("txt2").value;
var da=document.getElementById("fruit").value;
var xz=document.getElementById("select").value;
if(xz=="+"){da=parseInt(dy)+parseInt(ds);}
else if(xz=="-"){da=parseInt(dy)-parseInt(ds);}
else if(xz=="*"){da=parseInt(dy)*parseInt(ds);}
?else if(xz=="/"){da=parseInt(dy)/parseInt(ds);}
?}
? </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>
2015-08-21
把下面if函數里面用的da,換成document.getElementById('fruit').value 就能出現結果,因為你在前面已經讀取了那個結果的值,但是本身是為空的,當xz == ‘+’的話,da的值還是一開始就讀取的值為空……
2015-08-18
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</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>
<script type="text/javascript">
function count() {
var dy = document.getElementById("txt1").value;
var ds = document.getElementById("txt2").value;
var da = document.getElementById("fruit");
var xz = document.getElementById("select").value;
if (xz == "+") {
da.value = parseInt(dy) + parseInt(ds);
} else if (xz == "-") {
da.value = parseInt(dy) - parseInt(ds);
} else if (xz == "*") {
da.value = parseInt(dy) * parseInt(ds);
} else if (xz == "/") {
da.value = parseInt(dy) / parseInt(ds);
}
}
</script>
</html>
2015-08-17
怎么搞的? 求告知
2015-08-17
var da=document.getElementById("fruit");
da.value =?parseInt(dy)+parseInt(ds);
這么寫能行 不知道為什么