无法摆脱这种类型的错误

时间:2015-03-11 04:21:06

标签: javascript typeerror

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");

    }

}

1 个答案:

答案 0 :(得分:1)

toFixed()到数字方法,this.value是一个字符串,因此将this.value转换为数字。您可以根据需要使用parseInt()/parseFloat/unary operator来执行此操作

(+this.value).toFixed(2);