[英]How to apply Local Storage to a to-do list
I'm working on an app, and one section of this app is like a to-do list. 我正在开发一个应用程序,该应用程序的一部分就像一个待办事项清单。 The user can add and delete list-items.
用户可以添加和删除列表项。 I've been trying to apply local storage to this list, but I can't do it.
我一直在尝试将本地存储应用到此列表,但是我做不到。
HTML: HTML:
<input type="text" id="entrada" placeholder="" />
<a href="#" data-role="button" id="agregar">Add</a>
<ul id="list" data-role="listview">
</ul>
JS: JS:
$('#agregar').on('click', function()
{
$('#agregar').on('click', function(event) { $('#entrada').val("")})
var entrada = $('#entrada').val();
if($("#entrada").val() == '')
{ return false; }
$('#list').append( '<li><a hreft="#">'+entrada+<'</a></li>' );
$('#list').listview( 'refresh' );
}
)
here is a working example of the list save in local storage so even if you closed the page and opened it again the to-do list still exists http://codepen.io/mozzi/pen/mEwqzE 这是列表保存在本地存储中的一个有效示例,因此即使关闭页面并再次打开页面,待办事项列表仍然存在http://codepen.io/mozzi/pen/mEwqzE
this is the code you have to change : 这是您必须更改的代码:
$('#agregar').on('click', function() {
$('#agregar').on('click', function(event) {
$('#entrada').val("")
})
var entrada = $('#entrada').val();
if ($("#entrada").val() == '') {
return false;
}
$('#list').append('<li><a hreft="#">' + entrada + '</a></li>');
localStorage.setItem("todolist", $('#list').html());
$('#entrada').val("");
$('#list').listview('refresh');
})
$(function(){
$('#list').html(localStorage.getItem("todolist"));
})();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.