当前位置:网站首页>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>

边栏推荐
- golang正则regexp包使用-06-其他用法(特殊字符转换、查找正则共同前缀、切换贪婪模式、查询正则分组个数、查询正则分组名称、用正则切割、查询正则字串)
- I am in Zhongshan. Where can I open an account? Is it safe to open an account online?
- 附加:HikariCP连接池简述;(并没有深究,只是对HikariCP连接池有个基本认识)
- 关于#sql#的问题:SQL问题--账号多地登录的SQL代码
- Authorization of database
- Une citation classique de la nature humaine que vous ne pouvez pas ignorer
- 国信金太阳靠谱吗?开证券账户安全吗?
- Dreamcamera2 video recording, playing without sound, recording function is normal, using a third-party application for video recording, playing with sound
- Overview of orb-slam3 paper
- Wealth freedom skills: commercialize yourself
猜你喜欢
随机推荐
MySQL updates records based on the queried data
arduino字符串转16进制数 大彩串口屏用。
Notes on the 3rd harmonyos training in the studio
Wealth freedom skills: commercialize yourself
学习太极创客 — MQTT(五)发布、订阅和取消订阅
论文回顾:Unmixing-Based Soft Color Segmentation for Image Manipulation
Dual batteries in series, hardware design
2021-08-04
Analysis of the multiple evaluation system of children's programming
[QT] custom control - air quality dashboard
Camtasia 2022全新版超清录制电脑视频
Survival analysis based on ovarian data set
【哈希表】很简单的拉链法哈希结构,以至于效果太差,冲突太多,链表太长
经典模型——AlexNet
Vulhub replicate an ActiveMQ
Analysis of technological changes in social robots
Please advise tonghuashun which securities firm to choose for opening an account? Is it safe to open an account online?
Good news | congratulations on the addition of 5 new committers in Apache linkage (incubating) community
用元分析法驱动教育机器人的发展
ArrayList # sublist these four holes, you get caught accidentally









