我有个问题。我目前正在使用.prepend()
哪个将旧表行推到底部,而新表行出现在顶部。但是,我必须将表格行数限制为 10,这样做,一旦.prepend()
达到 10 行,最新的行将出现在表格的底部,然后再次向上工作,反之亦然。我想知道一种新行将永久出现在顶部的方式,<tbody>
同时将旧行推到底部。这是我的代码供参考。
// show the keys currently held in the specified type of storage in the
// specified table
function showStorageKeys(type, table, table1) {
// get the specified type of storage, i.e. local or session
var storage = window[type + 'Storage'];
// remove the rows in the specified table before we start
$(table + " > tbody > tr").remove();
$(table1 + " > tbody > tr").remove();
// loop through the existing keys in the storage and add them to the TBODY
// element as rows
for (var i = 0; i < storage.length; i++) {
var key = storage.key(i);
if ((key == "0") || (key == "1") || (key == "2") || (key == "3") || (key == "4") || (key == "5") || (key == "6") ||
(key == "7") || (key == "8") || (key == "9")) {
var details = storage.getItem(key);
details = details.split(";");
var lat = details[0];
var long = details[1];
var zoom = details[2];
var time = details[3];
var address = details[4];
//var date = details[5];
if ((address == undefined) || (time == undefined) || (address == "")) {
document.getElementById("dummy").value = "";
}
else {
$("#history tbody").prepend(
"<tr>" + "<td width='5%'>" + time + "</td>" +"<td>" + "<a href='JavaScript:getSite(" + lat + ',' + long + ',' + zoom + ")'>" + address +"</a>" +</td>" + "<td width='15%'>" + "<input type='submit' value='Remove' onclick='removeItem(\"" + type + "\", \"" + key + "\")'/>" + "</td>" + "</tr>");
}
}
}
]