jQuery 综合练习ToDoList
<div class="header">
<section>
<label for="">ToDoList</label>
<input type="text" id="title" name="title" placeholder="添加ToDo" required>
</section>
</div>
<section>
<h2>正在进行<span id="todocunt"></span></h2>
<ol id="todolist" class="demo-box">
<!-- <li>
<input type="checkbox" name="" id="">
<p>123</p>
<a href="#"></a>
</li> -->
</ol>
<h2>已经完成<span id="donecount"></span></h2>
<ul id="donelist"> </ul>
<footer>
Copyright © 2014 todolist.cn
</footer>
</section>
$(function () {
// localStorage.removeItem('todolist')
load();
$("#title").on("keydown", function (event) {
if (event.keyCode === 13) {
if ($(this).val() === "") {
alert("请输入内容")
} else {
var local = getDate();
// 把最新的数据追加给local数组
local.push({ title: $(this).val(), done: false })
// 把这个数组local 存储给本地存储
saveData(local);
load()
$(this).val("")
}
}
})
// 读取本地存储的数据
function getDate() {
var data = localStorage.getItem("todolist")
if (data !== null) {
return JSON.parse(data);
} else {
return [];
}
}
// 保存本地存储数据
function saveData(data) {
localStorage.setItem("todolist", JSON.stringify(data));
}
// todolist删除
$("ol,ul").on("click", "a", function () {
var data = getDate();
// 修改数据
var index = $(this).attr("id")
data.splice(index, 1)
// 保存到本地存储
saveData(data);
// 重新渲染页面
load()
})
// 选项操作
$("ol,ul").on("click", "input", function () {
var data = getDate();
//修改数据
var index = $(this).siblings("a").attr("id")
data[index].done = $(this).prop("checked")
// 保存本地存储
saveData(data)
// 重新渲染
load()
})
// 渲染数据
function load() {
// 读取本地存储数据
var data = getDate();
// 遍历之前需要清空ol里面的内容
$("ol,ul").empty()
var todoCount = 0;
var doneCount = 0;
$.each(data, function (i, n) {
if (n.done) {
$("ul").prepend("<li><input type='checkbox' checked='checked'> <p>" + n.title + "</p> <a href='javadcript:;' id=" + i + ">删除</a></li>")
doneCount++;
}
else {
$("ol").prepend("<li><input type='checkbox'> <p>" + n.title + "</p> <a href='javadcript:;' id=" + i + ">删除</a></li>");
todoCount++;
}
})
$("#todocunt").text(todoCount)
$("#donecount").text(doneCount)
}
})
body {
margin:;
}
.header {
height: 50px;
line-height: 50px;
background: rgba(47, 47, 47, 0.98);
}
section {
width: 600px;
padding: 0 10px;
margin: 0 auto;
}
label {
float: left;
width: 100px;
line-height: 50px;
color: #DDD;
font-size: 24px;
cursor: pointer;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.header input {
float: right;
width: 60%;
height: 24px;
margin-top: 12px;
text-indent: 10px;
border-radius: 5px;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.24), 0 1px 6px rgba(0, 0, 0, 0.45) inset;
border: none;
}
h2 {
position: relative;
}
ol,
ul {
padding:;
list-style: none;
}
li {
height: 32px;
line-height: 32px;
background: #fff;
position: relative;
margin-bottom: 10px;
padding: 0 45px;
border-radius: 3px;
border-left: 5px solid #629A9C;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
}
li input {
position: absolute;
top: 2px;
left: 10px;
width: 22px;
height: 22px;
cursor: pointer;
}
ul li {
border-left: 5px solid #999;
opacity: 0.5;
}
a,span {
position: absolute;
top: 2px;
right: 5px;
display: inline-block;
padding: 0 5px;
height: 20px;
border-radius: 20px;
background: #E6E6FA;
line-height: 22px;
text-align: center;
color: #666;
font-size: 14px;
}
css

jQuery 综合练习ToDoList的更多相关文章
- Dojo与jQuery综合比较分析
最近一直都在参与项目,无法抽空写些或者看些东西,周末抽了点时间看了下关于Dojo和Jquery的东西,在CSDN上看到一篇两个框架进行对比的文章,感觉写的不错,就拿了过来,没有别的意思,一来想保留下来 ...
- jquery综合
1.选择器性能比较: http://www.jcodecraeer.com/a/javascript/2012/0418/112.html http://developer.51cto.com/art ...
- jquery综合练习--模态对话框传值,删除,新增表格行
效果示例: 个人的练习代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- react综合案例-todolist、localstorage缓存数据
1.工具类storage.js var app ={ set(key,value){ localStorage.setItem(key,JSON.stringify(value)); }, get(k ...
- jquery 综合使用例子
效果如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...
- jQuery官网plugins栏目下那些不错的插件
前言: 很久以前就关注过jQuery官网plugins栏目下那些全是英文的插件,本人的英文水平很菜,想要全部看懂确实是件不易之事. 好在大部分的案例中都有 view-homepage 或 Try a ...
- 使用jquery和使用框架的区别
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- jQuery(*****)
参考1 参考2 1. jQuery 1. 选择器 $("") 1. 基本选择器 1. ID --> $("#d1") 2. 标签名 --> $(&q ...
- Vue (一) --- vue.js的快速入门使用
=-----------------------------------把现在的工作做好,才能幻想将来的事情,专注于眼前的事情,对于尚未发生的事情而陷入无休止的忧虑之中,对事情毫无帮助,反而为自己凭添 ...
随机推荐
- web 部署专题(四):压力测试(二)压力测试实例 flask 四种wsgi方式对比(tornado,Gunicorn,Twisted,Gevent)
使用工具:siege 代码结构: hello.py templates |--hello.html hello.py代码: from flask import Flask, render_templa ...
- 数据可视化之DAX篇(十七)Power BI表格总计行错误的终极解决方案
https://zhuanlan.zhihu.com/p/68183990 我在知识星球收到的问题中,关于表格和矩阵(以下统称表格)总计行错误算是常见的问题之一了,不少初学者甚为不解,在Excel透视 ...
- 数据可视化之分析篇(九)PowerBI数据分析实践第三弹 | 趋势分析法
https://zhuanlan.zhihu.com/p/133484654 以财务报表分析为例,介绍通用的分析方法论,整体架构如下图所示: (点击查看大图) 我会围绕这五种不同的方法论,逐步阐述他们 ...
- hihoCoder 1114 小Hi小Ho的惊天大作战:扫雷·一 最详细的解题报告
题目来源:小Hi小Ho的惊天大作战:扫雷·一 解题思路:因为只要确定了第一个是否有地雷就可以推算出后面是否有地雷(要么为0,要么为1,如果不是这两个值就说明这个方案行不通),如果两种可能中有一种成功, ...
- Redis 分布式锁(一)
前言 本文力争以最简单的语言,以博主自己对分布式锁的理解,按照自己的语言来描述分布式锁的概念.作用.原理.实现.如有错误,还请各位大佬海涵,恳请指正.分布式锁分两篇来讲解,本篇讲解客户端,下一篇讲解r ...
- 基于Python的HTTP接口自动化测试框架实现
今天我们来讲一下基于Python的HTTP接口自动化测试框架的实现,范例如下: 一.测试需求描述 对服务后台一系列的http接口功能测试. 输入:根据接口描述构造不同的参数输入值 输出:XML文件 e ...
- Burp Suite Target Module - 目标模块
模块目的之一:获取网站分析 1.从Proxy - HTTP history界面选中需要加入Target Scope的Host 地址,右击,选中Add to Scope. 2.打开Target - Sc ...
- java大数据最全课程学习笔记(5)--MapReduce精通(一)
目前CSDN,博客园,简书同步发表中,更多精彩欢迎访问我的gitee pages 目录 MapReduce精通(一) MapReduce入门 MapReduce定义 MapReduce优缺点 优点 缺 ...
- Azure Traffic Manager(二) 基于权重与基于优先级的路由策略为我们的Web项目提供负载均衡
一,引言 上一片文章我们使用 Azure Traffic Manager 分发用户请求,同时演示了两种路由策略,“Performance”,“Geographic”的两种方式,今天我们继续讲解 Tra ...
- vue如何使用excel导出后台数据
let params = { // 请求参数 要下载Excel的id 'id':this.excelId }; //导入的接口名 api_excel_exportExcel().then(res =& ...