【发布时间】:2017-11-15 00:29:50
【问题描述】:
附加到 div 的列表,我如何存储它们以便下次打开浏览器时附加的元素保持之前的状态。
$('#try').prepend('<li class="list-group-item danger">' + $('#dat').html() + '</li>');这是我要附加的内容。
//This is the empty div
<div id="dat" class="alert alert-danger">
</div>
/*below is my javascript code to append elements(ignore other functions)
this code basically appends the defects to the empty div*/
var queue = new Array();
function greet(greeting) {
console.log(greeting);
$('#dat').text(greeting);
}
function getRandom(arr) {
var rand = Math.random();
return arr[Math.floor(rand * arr.length)];
}
var greetings = [
"Hello 1",
"hello 2",
"hello 3",
"Hello 4",
"hello 5",
"hello 6",
"hello 7"
];
/*---------------------------*/
$(document).ready(function() {
ion.sound({
sounds: [
{ name: "glass" }
],
path: "Scripts/ui control/ring/",
preload: false,
volume: 10.0
});
setInterval(function() {
ion.sound.play("glass");
greet(getRandom(greetings));
$(".alert").fadeIn("fast").fadeOut(5000, function addMessage(msg) {
queue.push(msg);
$('#try').prepend('<li class="list-group-item danger">' + $('#dat').html() + '</li>');
if ($('.list-group-item').length > 9) {
//var msgToRemove = queue.shift();
//msgToRemove.remove();
$('.list-group-item:last').remove();
}
});
}, 8000);
});
【问题讨论】:
-
cookie 怎么样?你需要这样的东西:stackoverflow.com/a/4225071/8137468
标签: javascript jquery html