我的javascript中不断出现“uncaughtsyntaxerror:unexpectedtoken{”,我不知道为什么

我的javascript中不断出现“uncaughtsyntaxerror:unexpectedtoken{”,我不知道为什么,javascript,Javascript,我在我的学校为这个项目编程,在我的javascript中,我一直收到这个错误。请帮助。这将是非常感谢 var table,row,cell1,cell2,cell3 { table=document.getElementById("onlineAttendance"); studentInfo= JSON.parse(localStorage.getItem("studentRecord")); } function myFunction() { alert ("Your attend

我在我的学校为这个项目编程,在我的javascript中,我一直收到这个错误。请帮助。这将是非常感谢

var table,row,cell1,cell2,cell3 {
table=document.getElementById("onlineAttendance");
studentInfo= JSON.parse(localStorage.getItem("studentRecord"));
}
 function myFunction() {
    alert ("Your attendence is submitted");
}
function studentAttendance () {
for (var index=0;index<studentInfo.length;index++) {
    row=table.insertRow(index+1);
    cell1=row.insertCell(0);
    cell2=row.insertCell(1);
    cell3=row.insertCell(2);
    cell4=row.insertCell(3);
    cell1.innerHTML=studentInfo[0].studentNumber;
    cell2.innerHTML=studentInfo[0].firstName+" "+
        studentInfo[0].lastName;  
    cell3.innerHTML=studentInfo[0].absent;
    for (i=0; i<length; i++) 
        if (!document.getElementById(absent).checked)
        {
            studentInfo.points++;
}

有几个问题,首先你需要在你的var声明后加一个分号。你也在做不必要的块包装,但这并不是一个真正的问题,除非在尝试调试时,因为缩进应该是每个人都关心的问题

最后,您没有关闭最后一个函数和for循环,忽略缩进。但是,如果您只是在创建问题时忘记复制它们,则可能不需要它们

var table,row,cell1,cell2,cell3;

{
    table=document.getElementById("onlineAttendance");
    studentInfo= JSON.parse(localStorage.getItem("studentRecord"));
}

 function myFunction() {
    alert ("Your attendence is submitted");
}

function studentAttendance () {
    for (var index=0;index<studentInfo.length;index++) {
        row=table.insertRow(index+1);
        cell1=row.insertCell(0);
        cell2=row.insertCell(1);
        cell3=row.insertCell(2);
        cell4=row.insertCell(3);
        cell1.innerHTML=studentInfo[0].studentNumber;
        cell2.innerHTML=studentInfo[0].firstName+" "+
            studentInfo[0].lastName;  
        cell3.innerHTML=studentInfo[0].absent;
        for (i=0; i<length; i++) 
            if (!document.getElementById(absent).checked)
            {
                studentInfo.points++;
            }
        }
    }
}

您必须在for循环中关闭if语句。您的问题显然是您的不平衡{},或者您没有显示所有的代码….???var table、row、cell1、cell2、cell3{…看起来也不是声明变量的正确方法,最后的文本在做什么?