0
這是用來添加學生如何使用HTML,CSS和JavaScript將索引添加到本地存儲?
<!DOCTYPE html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
<script src="function.js"></script>
</head>
<header>
<nav>
<img src="logo.jpg"><h1 id="titt">North Park Clubs</h1>
<li><a href="attendance.html">Attendance</a></li>
</nav>
</header>
<body>
<h1>Add A Student</h1>
<input type="text" id="indx"></input>
<input type="text" id="sFirstName"></input>
<input type="text" id="sLastName"></input>
<input type="text" id="sNumber"></input>
<input type="text" id="sPoints"></input>
<input type="button" onclick="save()" value="Save"></input>
</body>
此頁面的HTML的頁面的HTML查看考勤
<!DOCTYPE html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
<script href="functions.js"></script>
</head>
<header>
<nav>
<img src="logo.jpg"><h1 id="titt">North Park Clubs</h1>
<li><a href="attendance.html">Attendance</a></li>
</nav>
</header>
<body onload="load()">
<table id="attendance">
<input type="button" value="Add Student" id="add" link="addStudent.html">
<tr>
<td></td>
<td>First Name</td>
<td>Last Name</td>
<td>Student Number</td>
<td>Points</td>
<td>Absent (If student is present leave this unchecked)</td>
</tr>
<td id="indx"></td>
<td id="sFirstName"></td>
<td id="sLastName"></td>
<td id="sNumber"></td>
<td id="sPoints"></td>
<td><input id="a" type="checkbox"></td>
</table>
</body>
這是我的JavaScript
var indx = [];
var sFirstName = [];
var sLastName = [];
var sNumber = [];
var sPoints = [];
var a = [];
var attendance = [];
var obj = JSON.parse(attendance);
function save(){
localStorage.setItem("idex", document.getElementById('indx').value);
localStorage.setItem("fName", document.getElementById('sFirstName').value);
localStorage.setItem("lName", document.getElementById('sLastName').value);
localStorage.setItem("numb", document.getElementById('sNumber').value);
}
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount) + 1;
} else {
localStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = "You have clicked the button " +
localStorage.clickcount + " time(s).";
//var fName = localStorage.sFirstName;
//var lName = localStorage.sLastName
//var numb = localStorage,sNumber
//onload document.getElementById('attendance');
function load(){
document.getElementById.idex;
document.getElementById.fName;
document.getElementById.lName;
document.getElementById.numb;
}
我我不太確定我做錯了什麼,所以解釋也會很棒!謝謝! :)
問題在哪裏? –
歡迎來到堆棧溢出。你的問題包含太多的代碼。你的頭銜很好,但我們無法理解你準備做什麼。請嘗試僅發佈與問題代碼相關的信息。 – Ifch0o1
爲什麼不使用localstorage來存儲對象數組而不是執行「setItem」爲什麼不創建一個名爲:* Entry *然後是'var list = GetItem(「data」)的對象。 SetItem(「Data」,list);'或更好:'localStorage.setItem(「data」,localStorage.getItem(「data」)。push(new Entry(i,f,l,num));' – Fallenreaper