javascript - 未捕获的语法错误 : Unexpected string in my Javascript code

标签 javascript html

我的代码中不断出现此错误,但我不明白为什么。请参阅我的 Javascript 第 29 行。

HTML

<link href="Styles12.css"; type="text/css" rel="stylesheet">
<link rel="stylesheet" href="Styles12.css"/>
<script src="registration.js"></script>
<body onload="studentAttendance()">
    <head>
        <style>
           table, td, th {
               border: 1px solid black;
           }
            th {
                background-color: beige;
                color:black;
            }
        </style>
    </head>
<h3 style= "font-size:25px; font-family:Impact"> ADD A STUDENT</h3>

名字:

姓氏:

学号:

    <button onclick = "save()"><p>+ADD TO ATTENDANCE</a></p> </button>
    <h2 style="font-size: 25px;font-family: Impact">Online attendance</h2>    
    <table id= "attendanceTable">
        <table border="10px">
            <thead>
                <tr>
                    <th> Student Name </th>
                    <th> Student Number </th>
                    <th> A </th>
                    <th> Points </th>
                    <th style="font-size:10px;font-align: left"><em><button> Edit:Add student(+)</a></button></em></th>
                    </th>
                 </tr>
            </thead>
    <tbody>
        <tr>
            <td></td>
            <td></td>
            <td><form action="demo_form.asp" method="get"></form></td>
            <td></td>
           <td> <input type="button" value="save"></input>
        <button>reset</button></td>
        </tr>
        <tbody>
            <tr>
                <td></td>
                <td></td>
                <td><form action="demo_form.asp" method="get"></form></td>
                <td></td>
            </tr>
            <tbody>
                <tr>
                    <td></td>
                    <td></td>
                    <td><form action="demo_form.asp" method="get"></form></td>
                    <td></td>
                </tr>
            </tbody>
        </table>

    <form>
    </form> 
    <button type="button" onlick="alert('Attendence submitted')">  <strong>SUBMIT</strong></button>
    <p id="demo"></p>
</body>

JAVASCRIPT

var studentNo = [];
var index = 0;
var studentInfo = [];
var newObj = [];

function save() { //this function takes values from the text box and stores them as an object studentInfo[index] = { studentNumber: document.getElementById("studentNo").value, firstname: document.getElementById("firstname").value, lastname: document.getElementById("lastname").value, }; index++;

    localStorage.setItem("studentRecord", JSON.stringify(studentInfo));
}

function studentAttendance() {
    newObj = JSON.parse(localStorage.getItem("studentRecord"));
    var table, row, cell1, cell2, cell3;
    table = document.getElementById("onlineAttendance");
    studentInfo = JSON.parse(localStorage.getItem("studentRecord"));
    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[index].studentNumber;
        cell2.innerHTML = studentInfo[index].firstName + " " +
            studentInfo[index].lastName;
        cell3.innerHTML = studentInfo[index].
        '<input type="checkbox" name="student attendance" value="absent" id="checkboxab"</input>';

    }

    function save() {
        if (document.getElementById('checkboxab').checked) {
            alert("checked");
        } else {
            alert("You didnt check it")
            studentInfo.points++
        }
    }
}

最佳答案

. 在php中使用来连接字符串

+ 在 javascript 中使用来连接字符串

尝试这样

cell3.innerHTML =studentInfo[index]+
        '<input type="checkbox" name="student attendance" value="absent" id="checkboxab"</input>';

关于javascript - 未捕获的语法错误 : Unexpected string in my Javascript code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30825368/

相关文章:

javascript - 从下拉框中获取选定的值并用于填充文本框 php javascript

html - 如何在使用多个类的单个元素上使用多个 CSS 伪类 **::before**

html - Angularjs <div ng-include> 不填充垂直视口(viewport)

javascript - 我需要帮助将矩形 append 一些深

javascript - Div重叠并且速度错误

javascript - 浏览器调整大小时实时更改

javascript - 如何在剑道中的单击事件中获取包含复选框的行

HTML5 数据库值不会停留在浏览器关闭时

html - Bootstrap 4 - 使表头粘性

javascript - 为什么使用 for 循环时表的格式错误?