javascript - To Do List using JQuery and LocalStorage -
hi guys i'm trying create todo list using jquery , local storage.
- if localstorage has values already, should populate when page loads (closing window , reopening retains "todo's")
- if item exists in list, show console message noting duplicate (using $.inarray)
- user should able add , remove items , have changes save automatically (using splice)
this have far:
<body> <h1>todo list</h1> <input id="input" type="text"><button id="add">add</button> <ul id="list"></ul> </body> <script src="http://code.jquery.com/jquery-2.1.3.min.js"></script> <script> if(window.localstorage !== undefined){ var storedata = { }; var input = $("#input").val(); $("#add").click(function (){ localstorage.setitem("input", json.stringify(input)); }); }; $(document).ready(function(){ var data = json.parse(localstorage.getitem("storedata")); $("#list").html(data); }); </script>
is wrong in code? how can add splice , check duplicates using $.inarray? thanks.
you setting 1 key input
, retrieving different key storedata
try changing
localstorage.setitem("input", json.stringify(input));
to
localstorage.setitem("storedata", json.stringify(input));
if trying store array need rethink add
functionality. right store value of input when page loads...which empty. , have no array work in code
i suggest @ code used in todomvc
Comments
Post a Comment