无法摆脱这种类型的错误
Cant get rid of this type Error
大家好....
我无法摆脱此代码第 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");
}
}
toFixed()
为数字方法,this.value
为字符串,因此将 this.value
转换为数字。您可以根据需要使用 parseInt()/parseFloat/unary operator
来完成此操作
(+this.value).toFixed(2);
大家好.... 我无法摆脱此代码第 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");
}
}
toFixed()
为数字方法,this.value
为字符串,因此将 this.value
转换为数字。您可以根据需要使用 parseInt()/parseFloat/unary operator
来完成此操作
(+this.value).toFixed(2);