Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';不要让NaN被0-trued rappy替换_Javascript_Jquery - Fatal编程技术网

Javascript Can';不要让NaN被0-trued rappy替换

Javascript Can';不要让NaN被0-trued rappy替换,javascript,jquery,Javascript,Jquery,似乎无法获取要替换为0的数字NaN错误。尝试使用rappy,但不适用于我 window.onload = function () { var first = document.getElementById('firstFieldId'), second = document.getElementById('secondFieldId'), third = document.getElementById('thirdFieldId'), fo

似乎无法获取要替换为
0
的数字
NaN
错误。尝试使用
rappy
,但不适用于我

window.onload = function () {
    var first = document.getElementById('firstFieldId'),
        second = document.getElementById('secondFieldId'),
        third = document.getElementById('thirdFieldId'),
        fourth = document.getElementById('fourthFieldId');

    first.onkeyup = function () {
        var value;

        // Get the value and remove the commas
        value = first.value.replace(/,/g, "");

        // Make it a number
        value = parseInt(value, 10);

        // Add one to it
        ++value;

        // Turn it back into a string
        value = String(value);

        // Put it in the other text box, formatted with commas
        second.value = numberWithCommas(value);
    };
    third.onkeyup = function () {
        var value;

        // Get the value and remove the commas
        value = third.value.replace(/,/g, "");

        // Make it a number
        value = parseInt(value, 10);

        // Add one to it
        ++value;

        // Turn it back into a string
        value = String(value);

        // Put it in the other text box, formatted with commas
        fourth.value = numberWithCommas(value);
    };

    function numberWithCommas(x) {
        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }
};
创建一个JSFIDLE-如果在第一个或第三个字段中输入一个数字,然后清除它,第二个或第四个字段将显示为
NaN
。。。它需要说
0

任何帮助都会很好

更换

++value;


@verrucktfuchs对不起,是
isNan
而不是
isNan
。这是一份工作单,非常感谢。工作起来很有魅力!
value = isNaN(value) ? 0 : value+1