我想写2个十进制数字,在这种情况下我不知道如何使用toFixed
?
<head>
<title>Calculate</title>
<script type="text/javascript">
function calcform(){
result.value = (number1.value - 32) / 1.8;
}
</script>
<body bgcolor="lightgreen">
<form>
<p><fieldset><legend>JavaScript</legend></p>
Fahrenheit degree:
<input type="text" id="number1" value="" size="10" /><br/>
<p>
Celsius degree:
<input type="text" id="result" value="" size="10" /><br/>
<p>
<input type="button" id="Calculate" value="Calculate" onclick="calcform()".toFixed(2) />
<input type="reset" value="Clear"/>
<p></fieldset></p>
</strong>
</form>
</body>
答案 0 :(得分:0)
尝试:
result.value = ((number1.value - 32) / 1.8).toFixed(2);