我正在申请积分。我如何检查复选框是否被选中,如果它是如何添加10,如果没有选中,我希望它什么都不做。这是JavaScript。 JS
Width="{Binding ElementName=DatagridName, Path=CellsPanelActualWidth}"
这里是一个JSfiddle:https://jsfiddle.net/RandomRainbow7/Lm574foy/ 小提琴不会显示一个人,所以如果你想要硬编码,否则就是另一个html页面。
if (localStorage.getItem("studentList") === null) {
localStorage.setItem("studentList", JSON.stringify([]));
}
studentList = JSON.parse(localStorage.getItem("studentList"));
function save() {
newStudent = {
"firstname": document.getElementById('sFirstName').value,
"lastname": document.getElementById('sLastName').value,
"studentnumber": document.getElementById('sNumber').value,
"points": document.getElementById('sPoints').value
};
studentList.push(newStudent);
localStorage.setItem("studentList", JSON.stringify(studentList));
};
table = document.getElementById("attendance");
for (i = 0; i < studentList.length; i++) {
row = table.insertRow(i + 1);
cell1 = row.insertCell(0);
cell2 = row.insertCell(1);
cell3 = row.insertCell(2);
cell4 = row.insertCell(3);
cell5 = row.insertCell(4);
cell1.innerHTML = studentList[i].firstname;
cell2.innerHTML = studentList[i].lastname;
cell3.innerHTML = studentList[i].studentnumber;
cell4.innerHTML = studentList[i].points;
cell5.innerHTML = "<input type=checkbox>";
}
function userName() { //this function takes values from the text box and stores them in objects
var studentList = {
studentNumber: document.getElementById("newUser").value + index,
lastName: document.getElementById("newlName").value + index,
firstName: document.getElementById("newfName").value + index
};
}
答案 0 :(得分:0)
您可以在json对象中存储“缺席”的信息以及学生的其他信息:
将其存储在save()
功能:
newStudent = {
"firstname": document.getElementById('sFirstName').value,
"lastname": document.getElementById('sLastName').value,
"studentnumber": document.getElementById('sNumber').value,
"points": document.getElementById('sPoints').value,
"absent": document.getElementById('sAbsent').checked
};
在表格的for-loop
中阅读:
cell1.innerHTML = studentList[i].firstname;
cell2.innerHTML = studentList[i].lastname;
cell3.innerHTML = studentList[i].studentnumber;
cell4.innerHTML = studentList[i].points;
cell5.innerHTML = "<input type=checkbox" + (studentList[i].absent === true) ? "checked>" : ">";
}
将其写在<h1>Add A Student</h1>
下的HTML中:
<input type="checkbox" id="sAbsent"></input>