1

脚本

<script type="text/javascript">
    function updatesum() {
    document.add_new_report.total.value = (document.add_new_report.cheque.value -0) + (document.add_new_report.cash.value -0);
    }
    </script>

入力フィールド

<input type="text" name="cheque" id="cheque" onChange="updatesum()" />
<br>
<input type="text" name="cash" id="cash" onChange="updatesum()" />

結果フィールド

<input type="text" id="total" readonly="readonly" name="total"  />

小切手に100.100 、現金に200を入力すると、合計が300.1と表示されますが、 300.100を表示したいのですが、 どうすればよいですか?

4

2 に答える 2

3

これを試して:

document.add_new_report.total.value = ((document.add_new_report.cheque.value -0) + (document.add_new_report.cash.value -0)).toFixed(3);
于 2013-01-08T20:04:32.337 に答える
0

.toFixed()メソッドを使用する必要があります

参照

function updatesum() {
document.add_new_report.total.value = 
  (
    (document.add_new_report.cheque.value -0) 
    + (document.add_new_report.cash.value -0)
    ).toFixed(3);
}

フィドルの例

于 2013-01-08T20:24:42.330 に答える