Я пытаюсь сохранить сообщения в «textBox» обратно в localStorage и добавить его к «logContent», но когда я обновил страницу, «logContent» по-прежнему пуст, но существует только оригинальный контент.Замените существующий контент = локальное хранилище + существующий контент. Javascript, WebStorage, LocalStorage
<body>
<div class="modal-body">
<input id="textBox" type="text" placeholder="Type Message" onkeydown="if (event.keyCode == 13) {enterPressed();}">
<p id="logContent">
-- Logging is created --
</p>
</div>
</body>
Вот мой Javascript, поэтому я хочу, чтобы заменить исходное содержание в «logContent» с textBox.value + оригинальным контентом в logContent и сделать дисплей все, все время, даже с обновлением страницы. Спасибо.
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0
var yyyy = today.getFullYear();
if (dd < 10) {
dd ='0'+ dd
}
if (mm < 10) {
mm ='0'+ mm
}
today = dd + '/' + mm + '/' + yyyy;
function enterPressed() {
localStorage.setItem("logs", document.getElementById("textBox").value);
if (textBox.value == "") {
}
else {
var logText = today + ":" + " " + localStorage.getItem("logs") + '<br>';
$("#logContent").prepend(logText); // Prepend textBox's content to the top of "logContent".
textBox.value = ""; // To clear the textBox after enter is pressed.
}
}
Кто-нибудь? Пожалуйста, ... :( –