javascript - 考勤应用程序未捕获语法错误 : Unexpected token {

标签 javascript

这是什么,是什么意思,为什么我会看到这个?我正在制作出勤申请,当我实时预览时,我看到 Uncaught SyntaxError: Unexpected token { .

function save() {
var first = document.getElementById('sFirstName');
var last = document.getElementById('sLastName');
var numb = document.getElementById('sNumber');
var pts = document.getElementById('pnts');
}

它似乎只出现在下面的行中。

 var studentInfo{

但不在这一行

first: document.getElementById('sFirstName').value,
last: document.getElementById('sLastName').value,
numb: document.getElementById('sNmber').value,
pnts: document.getElementById('pts').value
}
var newobj = [studentInfo];
        localStorage.setItem("student", JSON.stringify(studentInfo));
newobj = JSON.parse(localStorage.getItem("student"));
/*localStorage.setItem("studentInfo", JSON.stringify(studentInfo[index].value;
index = index + 0;
}*/
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);
                    cell5 = row.insertCell(4);
                    cell6 = row.insertCell(5);
                    cell7 = row.insertCell(6);

    cell1.innerHTML = studentInfo[index].firstName + studentInfo[index].lastName
    cell2.innerHTML = studentInfo[index].studentNumber;
    cell3.innerHTML = studentInfo[index].pnts;
}



function userName() { //this function takes values from the text box and stores them in objects

    var studentInfo = {
        studentNumber: document.getElementById("newUser").value + index,
        lastName: document.getElementById("newlName").value + index,
        firstName: document.getElementById("newfName").value + index

    }; 
}

代码按照我编写的顺序排列。

最佳答案

语法应该是

var studentInfo = {...
               ^^^^ 

您缺少赋值运算符

关于javascript - 考勤应用程序未捕获语法错误 : Unexpected token {,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30667833/

相关文章:

javascript - 如何在 Electron.js 中保存在 Canvas 上绘制的图像

javascript - append 到具有多个输入值的列表

javascript - 从 javascript 保存 3 个 php 变量

javascript - 如何访问不同域的php文件

javascript - 我可以有一个没有值的 JavaScript 对象键吗

javascript - HTML DOM 节点丢失事件

javascript - 如何在aspx页面中的repeater ItemDataBound函数中传递Control.ClientID?

javascript - 非常简单,非常流畅,JavaScript 跑马灯

javascript - setTimeout问题,没有超时

javascript 不工作文本区域