javascript 需要一个标识符,却看到了 ')'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13972467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 20:21:12  来源:igfitidea点击:

Expected an identifier and instead saw ')'

javascriptjslint

提问by GibboK

I receive this error,

我收到此错误,

 Expected an identifier and instead saw ')'.

in this lines of code. Any how to fix it?

在这行代码中。任何如何修复它?

   for (; index < nPageFullItemCnt; index++) {
        strIndex = "0" + index;
        keyIndex = "popup_item_" + strIndex.substr(strIndex.length - 2, 2);
        keyItem = document.getElementById(keyIndex);

        setPopupKeyText(keyIndex, " ");

        keyItem.className = "popupLangItemNone";
        keyItem.langId = "";
    }

采纳答案by BenM

You're not passing in the first parameter to the for()loop:

您没有将第一个参数传递给for()循环:

for (index = 0; index < nPageFullItemCnt; index++) 
{
    /* .. */
}

回答by Cerbrus

This bit:

这一点:

for (; index

Is causing that error. The code should validate if you do this:

导致该错误。如果您这样做,代码应该验证:

for (0; index

(As I assume you're not passing the first parameter, on purpose)

(因为我假设您没有故意传递第一个参数)

However, I'd suggest using a whileloop, instead of a for, if you're not going to make use of the [initialization]; [condition]; [final-expression]properties in a forloop.

但是,while如果您不打算[initialization]; [condition]; [final-expression]for循环中使用属性,我建议使用循环而不是 for 。

while(index < nPageFullItemCnt){
    // Do stuff;
    index++;
}

Technically, the 3 parameters are all optional, but some code validators can throw a error if they're missing.

从技术上讲,这 3 个参数都是可选的,但是如果缺少某些代码验证器,则可能会引发错误。