0

下面的代码correctSNILS最终true在 Firefox(这是正确的)和falseIE7 中。如何识别为什么?

var value = "02324423703";
var correctSNILS = false;
if (value.length == 11) {
    var controlDigits = value.slice(9);
    var SNILS = value.slice(0, 9);
    if (SNILS < 1001998) {
        correctSNILS = true;
    } else {
        var total = SNILS.length;
        var result = 0;
        for (var i = 0; i < total; i++) {
            result += (total - i) * SNILS[i];
        }
        if (result == 100 || result == 101) result = "00";
        if (result > 101) result %= 101;
        if (result == controlDigits) correctSNILS = true;
    }
}
$("#result").text(correctSNILS);

演示

4

1 回答 1

3

您不能在 IE7 中将 String 作为数组访问:

result += (total - i) * SNILS[i];

将其更改为使用charAt字符串函数:

result += (total - i) * SNILS.charAt(i);
于 2012-10-18T19:10:51.107 回答