在下面的函數中,我將包含num.toFixed(2);使「總計」的估價師顯示爲小數點後兩位(價格)?using num.toFixed();
function calculate_total(id) {
var theForm = document.getElementById(id)
total = 0;
if (theForm.toyCar.checked) {
total += parseFloat(theForm.toyCar.value);
}
theForm.total.value = total;
theForm.GrandTotal.value = total + (total*0.18);
}
這是輸出:
<input type="button" name="CheckValue" value = "Calculate cost" onclick="calculate_total(this.form.id)" />
Total: <input type="text" name="total" id="total" size="10" readonly="readonly" />
凡你輸出了嗎? – epascarello 2013-02-25 14:54:42