当前位置:网站首页>todolist未完成,已完成
todolist未完成,已完成
2022-06-26 02:49:00 【小菜鸟码住】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>storage</title>
</head>
<body>
<input type="text" required id="inp">
<h2>未完成<span id="num">0</span></h2>
<ul id="list">
</ul>
<h2>已完成</h2>
<ul id="com">
</ul>
<script>
var inp = document.getElementById('inp');
var list = document.getElementById('list');
var com = document.getElementById('com');
if(localStorage.getItem('data')){
var todo = localStorage.getItem('data');
var arr = JSON.parse(todo);
var arr1 = [];
}else{
var arr = [];
var arr1 = [];
}
function init(){
list.innerHTML = '';
for(var i=0;i<arr.length;i++){
list.innerHTML += '<li index='+i+'><input type="checkbox">'+arr[i]+'<button>删除</button></li>'
}//封装一个函数
}
init();
inp.onkeydown = function(e){
if(e.keyCode === 13){
arr.push(inp.value);
num.innerHTML = arr.length;
localStorage.setItem('data',JSON.stringify(arr));
list.innerHTML += '<li><input type="checkbox">'+inp.value+'<button>删除</button></li>'
}
}
list.onclick = function(e){
if(e.target.nodeName==='INPUT'){
var idx = e.target.parentNode.getAttribute('index');
var last = arr.splice(idx,1)[0];
num.innerHTML = arr.length;
arr1.push(last);
// list.removeChild(e.target.parentNode);
init();
com.innerHTML += '<li><input checked type="checkbox">'+last+'<button>删除</button></li>'
}
if(e.target.nodeName==='BUTTON'){
var idx = e.target.parentNode.getAttribute('index');
var last = arr.splice(idx,1)[0];
init();
}
}
// var arr = {name:123};
// localStorage.setItem('name',JSON.stringify(arr));
// var obj = JSON.parse(localStorage.getItem('name'));
// console.log(obj);
// localStorage.setItem('name','zhangsan');
</script>
</body>
</html>
边栏推荐
- What can Arthas do for you?
- Using meta analysis to drive the development of educational robot
- The role of children's programming in promoting traditional disciplines in China
- 计组笔记 数据表示与运算 校验码部分
- 用元分析法驱动教育机器人的发展
- On virtual memory and oom in project development
- Cox regression model
- Literature reading --- optimize RNA SEQ research to study herbicide resistance (review)
- 经典模型——AlexNet
- How to adjust face input size
猜你喜欢
Oracle connectivity issues and Solutions
培育项目式Steam教育理念下的儿童创造力
kotlin快速上手
Analysis of technological changes in social robots
Learn Tai Chi Maker - mqtt (IV) server connection operation
How to prompt
What can Arthas do for you?
OpenAPI 3.0 specification - Food Guide
Business process diagram design
[machinetranslation] - Calculation of Bleu value
随机推荐
论文回顾:Unmixing-Based Soft Color Segmentation for Image Manipulation
Camtasia 2022 new ultra clear recording computer video
Is it safe to open an account in flush online? How to open a brokerage account online
经典模型——AlexNet
解析社交机器人中的技术变革
Translation notes of orb-slam series papers
数字孪生智慧水务,突破海绵城市发展困境
360 秒了解 SmartX 超融合基础设施
How to delete gridlines in ggplot2 (with examples)
【哈希表】很简单的拉链法哈希结构,以至于效果太差,冲突太多,链表太长
ArrayList # sublist these four holes, you get caught accidentally
校园创客空间的硬件造物原理
How to adjust face input size
Distributed e-commerce project grain mall learning notes < 3 >
Authorization of database
HL7Exception: Can‘t XML-encode a GenericMessage. Message must have a recognized struct
[system architecture] - how to evaluate software architecture
学习太极创客 — MQTT(五)发布、订阅和取消订阅
[flask introduction series] flask processing request and response
Matlab| short term load forecasting of power system based on BP neural network