无法摆脱这种类型的错误

Cant get rid of this type Error

本文关键字:类型 错误 种类      更新时间:2023-09-26

嘿伙计们....我无法摆脱此代码第 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);