前端学习(1046):todolist删除数据1
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                前端学习(1046):todolist删除数据1
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
                                
                            
                            
                             
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>todoList待辦事項(xiàng)</title><script src="./js/jquery.min.js"></script>
</head><body><header><section><label for="title">ToDoList</label><input type="text" id="title" placeholder="添加ToDo"></section></header><section><h2>正在進(jìn)行<span id="rodocount"></span></h2><ol id="todolist" class="demo-box"></ol><h2>已經(jīng)完成<span id="rodocount"></span></h2><ul id="donelist"></ul></section><footer>Copyright ©2014 todolist.cn</footer><script>var todolist = [{title: '我今天吃了八個(gè)饅頭',done: false}, {title: '我今天學(xué)習(xí)jq',done: false}, ];localStorage.setItem("todo", JSON.stringify(todolist));//本地的數(shù)組轉(zhuǎn)換為json.stringfy();var data = localStorage.getItem("todo");console.log(typeof data);//獲取本地存儲(chǔ)數(shù)據(jù)需要把字符串?dāng)?shù)據(jù)轉(zhuǎn)換為對(duì)象形式j(luò)son.parsedata = JSON.parse(data);console.log(data);$(function() {//todolist渲染到界面load();//按下回車(chē) 把完整數(shù)據(jù)存儲(chǔ)到本地存儲(chǔ)里面$("#title").on("keydown", function(event) {if (event.keyCode === 13) {//先讀取本地存儲(chǔ)原來(lái)的數(shù)據(jù)var local = getDate();console.log(local);//把local數(shù)組更新元素local.push({title: $(this).val(),done: false});//把這個(gè)數(shù)組給本地存儲(chǔ)saveDate(local);//todolist渲染到界面load();}});//todolist刪除事件$("ol").on("click", "a", function() {//獲取本地存儲(chǔ)var data = getDate();console.log(data);//修改數(shù)據(jù)var index = $(this).attr("id");console.log(index);});//讀取本地存儲(chǔ)的數(shù)據(jù)function getDate() {var data = localStorage.getItem("todolist");if (data !== null) {//本地存儲(chǔ)里面的數(shù)據(jù)是字符串格式的return JSON.parse(data);} else {//返回一個(gè)數(shù)組return [];}}//保存數(shù)據(jù)function saveDate(data) {localStorage.setItem("todolist", JSON.stringify(data));}//渲染數(shù)據(jù)function load() {//讀取本地的數(shù)據(jù)var data = getDate(data);console.log(data);//遍歷之前清空$("ol").empty();//遍歷整個(gè)數(shù)據(jù)$.each(data, function(i, n) {console.log(n);$("ol").prepend("<li><input type='checkbox'><p>" + n.title +"</p><a href='javascript:;'></a></li> id=" + i + "");})}});</script>
</body></html> 
                        
                        
                        ?
總結(jié)
以上是生活随笔為你收集整理的前端学习(1046):todolist删除数据1的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
                            
                        - 上一篇: Foobar2000播放软件的玄学
 - 下一篇: 查看计算机数字证书,数字证书认不到怎么办