Heys Guys .... 我无法解决此代码第4行的类型错误。 有任何建议...... ???
function update() {
var numRegExp = /^\d*(\.\d{0,2})?$/;
if (numRegExp.test(this.value) !== false){
(this.value).toFixed(2);
for (var i = 1; i < 4; i++) {
document.forms[0].elements["sub" + i].value = calcRow(i).toFixed(2);
document.forms[0].total.value = calcTotal().toFixed(2);
}
}
else {
alert("Invalid currency value");
(this.value = "0.00");
}
}
答案 0 :(得分:1)
toFixed()
到数字方法,this.value
是一个字符串,因此将this.value
转换为数字。您可以根据需要使用parseInt()/parseFloat/unary operator
来执行此操作
(+this.value).toFixed(2);