如何在触摸之前让每个输入等于零,这样我就不会得到错误,直到每个输入完成并且没有在输入字段中显示它。这也是为了金钱和我努力得到两个小数点的东西。谢谢
<td>Subtotal</td>
<td class="total" id="tot" for="tot">
<input type="total" id="total">
<script type="text/javascript">
function myFunction()
{
var answer = document.getElementById('total');
var n = 0
var x = document.getElementById('itemprice');
var y = document.getElementById('itemprice1');
var z = document.getElementById('itemprice2');
//var d = document.getElementsById('itemprice3');
// parseFloat converts to values, otherwise you'll concatenate the strings.
answer.value = parseFloat(x[0].value) + parseFloat(y[0].value) + parseFloat(z[0].value); // + d.value;
}
</script>
</td>
答案 0 :(得分:1)
将商品价格设为零默认值:
<input type="total" id="itemprice" value="0.00">