js仿toDoList(待办事项)练习
JS的一个小练习
展示成果
话不多说
html骨架

<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>待办事项(toDoList)</title>
<link rel="stylesheet" href="Demo.css">
<script src="./Common.js"></script>
<script src="./Demo.js"></script>
</head> <body>
<div class="container">
<header><img src="./title.svg" alt=""><p class="header">待办事项列表</p></header>
<div class="txt">
<input type="text" id="txt" placeholder="添加今日待办事项~~">
<button id="btnAdd">添加</button>
</div>
<div class="liList">
<span class="ev">~今天我需要~</span>
<ul id="ul"> </ul>
</div>
<div class="select">
<p id="count">今日还剩下0个</p>
<button id="all">all</button>
<button id="Active">未完成</button>
<button id="Complete">已完成</button>
<button id="CompleteClear">清楚已完成待办</button>
</div>
</div>
</body> </html>
css样式

@font-face {
font-family: myFont;
src: url(/字体/01223131/今年也要加油鸭-三极字库.ttf);
}
*{
padding: 0;
margin: 0;
box-sizing: border-box;
user-select: none;
}
*:focus{
outline: none;
}
html{
font-family: myFont;
font-size: 18px;
}
body{
display: flex;
background-image: linear-gradient(90deg,#ffafbd,#ffc3a0);
background-repeat: no-repeat;
min-height: 100vh;
}
li{
list-style: none;
}
.container{
display: flex;
flex-direction: column;
padding: 1rem;
margin: 7rem auto;
background-color: #fff;
width: 27rem;
border-radius: 10px;
box-shadow: 4px 5px 15px 0px #999;
justify-content: space-between;
align-self: flex-start;
}
header{
display: flex;
justify-content: flex-start;
}
header>img{
width: 80px;
height: 60px;
margin-left: 5rem;
transform: rotate(-3deg);
}
.header{
width: 161px;
height: 40px;
font-size: 1.3rem;
padding: .25em .8em .15em;
border-radius: 20% 5% 20% 5%/5% 20% 25% 20%;
background-color: #fe7345;
text-align: center;
line-height: 30px;
transform: rotate(3deg);
margin-top: 10px;
color: #fff;
}
.txt{
margin-top: 2rem;
display: flex;
justify-content: space-around;
}
#txt{
width: 18rem;
height: 2rem;
font-size: 1rem;
border: #fe7345 3px dashed;
border-top: none;
border-left: none;
border-right: none;
font-family: myFont;
}
#btnAdd{
width: 100px;
background-color:orange;
border-radius: 47% 42% 17% 24%/28% 39% 52% 43%;
border: none;
transform: rotate(10deg);
transition:all .5s cubic-bezier(.175,.885,.32,1.275);
color: #fff;
font-family: myFont;
}
#btnAdd:hover{
box-shadow: 4px 5px 5px 0px #999;
}
.ev{
font-size: 1.2rem;
display: block;
text-align: left;
margin: .5rem auto;
}
.liList{
margin-top: 1rem;
}
#ul{
padding: 1rem;
border: 1px dashed #eee;
border-radius: 10px;
}
#ul>li{
display: flex;
margin-top: 1rem;
line-height: 2rem;
justify-content: space-between;
border-radius: 5px;
padding: 5px;
}
#ul>li:first-child{
margin-top: 0px;
}
#ul>li>div{
display: flex;
}
#ul>li>div>p{
margin-left: .5rem;
width: 300px;
overflow: hidden;
text-overflow: ellipsis;
-webkit-text-overflow:ellipsis;
}
.btnRemove{
height: 1.5rem;
width: 1.5rem;
border: none;
margin-top: .3rem;
background-color: transparent;
transition: all .3s 0ms;
}
.btnRemove:hover{
background-color: rgba(225, 225, 225, 0.5);
backdrop-filter: blur(4px) saturate(150%);
border-radius: 1.5rem;
}
.select{
display: flex;
}
.select>p{
font-size: .8rem;
margin-top: .7rem;
}
.select>button{
background-color: #fe7345;
border: none;
border-radius: 5px;
margin-left: 15px;
min-width: 30px;
font-size: 1rem;
margin-top: .5rem;
font-size: .9rem;
padding: 3px;
color: white;
font-family: myFont;
}
.done{
text-decoration:line-through;
}
.selectItem{
background-color: #fe7345;
color: white;
}
.hidden{
display: none !important;
}
.animate{
animation: animate .75s ease-in-out both;
}
@keyframes animate {
0%{
transform:rotateX(90deg);
opacity: 0;
}
40%{
transform:rotateX(-10deg);
}
70%{
transform:rotateX(10deg);
}
100%{
transform:rotateX(0deg);
opacity: 1;
}
}
原生js
Common.js

function $Id(id) {
return document.getElementById(id);
}
function $cls(clsName){
return document.getElementsByClassName(clsName);
}
function $tag(tagName){
return document.getElementsByTagName(tagName);
}
function $(clsName) {
return document.querySelectorAll(clsName);
}
function $one(clsOne) {
return document.querySelector(clsOne);
}
Demo.js

(function (win) {
win.addEventListener('load', () => {
$one('#btnAdd').addEventListener('mousedown', () => {
$one('#btnAdd').style.transform = 'rotate(0deg)';
if ($one('#txt').value.length > 0) {
//获取ul
var ul = $one('#ul');
//创建li
var li = document.createElement('li');
//创建包含复选框和span的div
var liCls = document.createElement('div');
//创建input元素
var checkBox = document.createElement('input');
//创建span显示复选框内容
var p = document.createElement('p');
//创建删除按钮
var btnRemove = document.createElement('button');
//删除按钮添加样式类名
btnRemove.classList.add('btnRemove');
btnRemove.innerText = 'X';
//指定input的类型
checkBox.type = 'checkBox';
//获取文本框内容,并赋值给复选框
checkBox.value = $one('#txt').value;
//赋值给span元素
p.innerText = checkBox.value;
//添加到包含元素
liCls.appendChild(checkBox);
liCls.appendChild(p);
li.appendChild(liCls);
li.appendChild(btnRemove);
ul.appendChild(li);
//清空文本框
$one('#txt').value = '';
checkBox.addEventListener('click', () => {
checkBox.nextSibling.classList.toggle('done');
if (checkBox.checked) {
li.classList.add('selectItem');
btnRemove.classList.add('selectItem');
} else {
li.classList.remove('selectItem');
btnRemove.classList.remove('selectItem');
}
checkBox.parentNode.parentNode.classList.toggle('animate');
CompleteCount();
});
p.addEventListener('mousedown', () => {
if (p.previousSibling.checked) {
p.previousSibling.checked = false;
} else {
p.previousSibling.checked = true;
}
li.classList.toggle('selectItem');
btnRemove.classList.toggle('selectItem');
checkBox.nextSibling.classList.toggle('done');
checkBox.parentNode.parentNode.classList.toggle('animate');
CompleteCount();
});
btnRemove.addEventListener('click', () => {
li.remove();
CompleteCount();
});
CompleteCount();
}
CompleteCount();
});
$one('#btnAdd').addEventListener('mouseup', () => {
$one('#btnAdd').style.transform = 'rotate(10deg)';
});
$one('#btnAdd').addEventListener('mouseleave', () => {
$one('#btnAdd').style.transform = 'rotate(10deg)';
});
$one('#all').addEventListener('click', () => {
for (const li of $('#ul>li>div>p')) {
li.parentNode.parentNode.classList.remove('hidden');
}
});
$one('#Active').addEventListener('click', () => {
for (const li of $('#ul>li>div>p')) {
if (!li.classList.contains('done')) {
li.parentNode.parentNode.classList.remove('hidden');
count++;
} else {
li.parentNode.parentNode.classList.add('hidden');
count--;
}
}
});
$one('#Complete').addEventListener('click', () => {
for (const li of $('#ul>li>div>p')) {
if (!li.classList.contains('done')) {
li.parentNode.parentNode.classList.add('hidden');
} else {
li.parentNode.parentNode.classList.remove('hidden');
}
}
});
$one('#CompleteClear').addEventListener('click', () => {
for (const li of $('#ul>li>div>p')) {
if (li.classList.contains('done')) {
li.parentNode.parentNode.remove();
}
}
});
function CompleteCount() {
var num = 0;
for (const li of $('#ul>li>div>p')) {
if (!li.classList.contains('done')) {
num++;
}
}
$one('#count').innerText = `今日还剩下${num}个`;
}
});
})(window);
转载请声明本文地址https://www.cnblogs.com/snail-wn/articles/16578307.html
js仿toDoList(待办事项)练习的更多相关文章
- todolist待办事项
使用html/css原生js实现待办事项列表: 支持添加待办事项,删除待办事项,切换待办事项的状态(正在进行,已经完成) 支持对正在进行以及已经完成事项编辑(单击内容即可编辑) 源代码:链接:http ...
- 基于html实现一个todolist待办事项
index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- vue todolist待办事项完整
<template> <div id="app"> <input type="text" v-model='todo' @keyd ...
- vue2.* 事件结合双向数据绑定、模块化以及封装Storage实现todolist 待办事项 已经完成 和进行中持久化 06
ceshi.vue <template> <div id="app"> <input type='text' v-model='todo' @keyd ...
- Vue 事件结合双向数据绑定实现todolist 待办事项 已经完成 和进行中
<template> <div id="app"> <input type="text" v-model='todo' @keyd ...
- vue.js--基础 事件结合双向数据绑定实现todolist 待办事项 已经完成 和进行中,键盘事件
<template> <div id="app"> <h1>{{ msg }}</h1> <input type=" ...
- jQuery模仿ToDoList实现简单的待办事项列表
功能:在文本框中输入待办事项按下回车后,事项会出现在未完成列表中:点击未完成事项前边的复选框后,该事项会出现在已完成列表中,反之亦然:点击删除按钮会删除该事项:双击事项可以修改事项的内容.待办事项的数 ...
- Javascript之网页版待办事项
本文使用原生JS实现站点 http://www.todolist.cn/ 的基本功能. 其中页面的HTML布局和CSS样式取用原站,JS部分为自己编写. 效果图 完整代码 HTML.JS部分 < ...
- 使用vue实现简单的待办事项
待办事项 效果图 目录结构 详细代码 AddNew.vue <template> <div> <input v-model="content"/> ...
随机推荐
- 如何在 pyqt 中自定义工具提示 ToolTip
前言 Qt 自带的工具提示样式不太好看,就算加了样式表也时不时会失效,同时工具提示没有阴影,看起来就更难受了.所以本篇博客将会介绍自定义工具提示的方法,效果如下图所示: 实现过程 工具提示其实就是一个 ...
- antdVue问题
antdVue框架问题 #(1)slot/slot-scope插槽问题 一般用于表格数据渲染 eg: <span slot="user" slot-scope="t ...
- Simple, Fast Malicious Multiparty Private Set Intersection-解读
文本记录阅读该论文的笔记. 这是文章框架,来自视频. 介绍 本文主要解决恶意攻击下安全的多方PSI,主要用到两大技术OPPRF和OKVS,构造合谋和不合谋的协议. 基础知识 OPPRF 这部分在OPR ...
- GDKOI 2021 Day1 TG 。。。
看着一群群比 LHF , HQX 还强的大佬涌进了机房,本蒟蒻表示慌得一批 T1 讲题人说最简单的签到题本蒟蒻表示... \(Update\) 用 ds , dt 两个变量记录点 i 连向 s 或 t ...
- flowable如何适配国产数据库达梦
前言 flowable6.4.1流程引擎官方支持的数据库有:MySQL.hsql.Oracle.DB2 .postgres.SQL Server.H2.对于其他类型的数据库如何支持,尤其是国产数据库的 ...
- cool-admin vite-vue3 打包部署 nginx代理设置
location /api {rewrite ^/api/(.*)$ /$1 break;proxy_pass http://xxx.com;}location /socket.io {rewrite ...
- springboot执行流程
构造方法初始化,创建一个新的实例,这个应用程序的上下文要从指定的来源加载bean public SpringApplication(ResourceLoaderresourceLoader,Class ...
- 探索链路追踪在.NET6工业物联网项目的应用
ExploringIoTDistributedTracingNet6 如果觉得有用,请留言学到了. 已经会了的老哥,请留言就这? 可能遇到的问题 工业物联网项目自上而下一般分为ERP.Mes.SCAD ...
- 《Java基础——IO流》
Java基础--IO流 一.字节流: 1.输入流 (InputStream) 规则: 此处用于读取txt文件中的内容. 代码: import java.io.*; public c ...
- CVE-2021-3156漏洞复现
CVE-2021-3156linux sudo 权限提升 版本ubantu18.04 使用这个命令可以是普通用户直接提升至管理员权限. 手动测试终端输入 sudoedit -s / 不知道什么原因ub ...