我有這個腳本,當按鈕被按下時,它添加一個按鈕值的結果。該功能的工作完全是,因爲它應該,但我需要讓我像十進制值工作: 1,00245使JavaScript工作與小數位
下面是代碼:
<html>
<head>
<script>
function pushButton(buttonValue) {
if (buttonValue == 'C') {
document.getElementById('screen').value = '0';
}
else {//this is where most changes occured
var x= document.getElementById('screen').value
x =parseInt(x)+ parseInt(buttonValue);
document.getElementById('screen').value=x;
}
}
function calculate(equation) {
var answer = eval(equation);
document.getElementById('screen').value = answer;
}
</script>
</head>
<body>
<table class="calc" cellpadding=10>
<tr><td colspan=3><input class="calc" id="screen" value='0'type="text"></td></tr>
<tr>
<td><input class="calc" type="button" value=1 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=2 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=3 onclick="pushButton(this.value);"></td>
</tr>
<tr>
<td><input class="calc" type="button" value=4 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=5 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=6 onclick="pushButton(this.value);"></td>
</tr>
<tr>
<td><input class="calc" type="button" value=7 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=8 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=9 onclick="pushButton(this.value);"></td>
</tr>
<tr>
<td><input class="calc" type="button" value='C' onclick="pushButton(this.value);"></td>
</tr>
</table>
</body>
</html>
我已經閱讀了幾次這個問題,而且根本不清楚要問什麼。閱讀代碼,我發現至少有一個函數'calculate',這裏沒有調用。你想做什麼? –