<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 &copy; 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的更多相关文章

  1. Dojo与jQuery综合比较分析

    最近一直都在参与项目,无法抽空写些或者看些东西,周末抽了点时间看了下关于Dojo和Jquery的东西,在CSDN上看到一篇两个框架进行对比的文章,感觉写的不错,就拿了过来,没有别的意思,一来想保留下来 ...

  2. jquery综合

    1.选择器性能比较: http://www.jcodecraeer.com/a/javascript/2012/0418/112.html http://developer.51cto.com/art ...

  3. jquery综合练习--模态对话框传值,删除,新增表格行

    效果示例: 个人的练习代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  4. react综合案例-todolist、localstorage缓存数据

    1.工具类storage.js var app ={ set(key,value){ localStorage.setItem(key,JSON.stringify(value)); }, get(k ...

  5. jquery 综合使用例子

    效果如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

  6. jQuery官网plugins栏目下那些不错的插件

    前言: 很久以前就关注过jQuery官网plugins栏目下那些全是英文的插件,本人的英文水平很菜,想要全部看懂确实是件不易之事. 好在大部分的案例中都有 view-homepage 或 Try a ...

  7. 使用jquery和使用框架的区别

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. jQuery(*****)

    参考1 参考2 1. jQuery 1. 选择器 $("") 1. 基本选择器 1. ID --> $("#d1") 2. 标签名 --> $(&q ...

  9. Vue (一) --- vue.js的快速入门使用

    =-----------------------------------把现在的工作做好,才能幻想将来的事情,专注于眼前的事情,对于尚未发生的事情而陷入无休止的忧虑之中,对事情毫无帮助,反而为自己凭添 ...

随机推荐

  1. java 面向对象(十九):关键字:static

    static:静态的1.可以用来修饰的结构:主要用来修饰类的内部结构属性.方法.代码块.内部类2.static修饰属性:静态变量(或类变量) 2.1 属性,是否使用static修饰,又分为:静态属性 ...

  2. 机器学习实战基础(二十九):决策树(二)DecisionTreeClassifier与红酒数据集

    DecisionTreeClassifier与红酒数据集 1 sklearn.tree.DecisionTreeClassifier class sklearn.tree.DecisionTreeCla ...

  3. javascript基础(三): 操作DOM对象(重点)

    DOM:文档对象模型 核心 浏览器网页就是一个Dom树形结构! 更新:更新Dom节点 遍历Dom节点:得到Dom节点 删除:删除一个Dom节点 添加:添加一个新的节点 要操作一个Dom节点,就必须要先 ...

  4. 大牛聊Java并发编程原理之 线程的互斥与协作机制

    可能在synchronized关键字的实现原理中,你已经知道了它的底层是使用Monitor的相关指令来实现的,但是还不清楚Monitor的具体细节.本文将让你彻底Monitor的底层实现原理. 管程 ...

  5. Kafka Eagle V2.0.0新版预览

    1.概述 Kafka Eagle是一款用于管理Kafka的监控系统,且完全开源.当前Kafka Eagle发布了2.0.0版本.今天笔者就为大家来介绍一下2.0.0更新了哪些功能. 官网地址:http ...

  6. 【翻译】Scriban README 文本模板语言和.NET引擎

    scriban Scriban是一种快速.强大.安全和轻量级的文本模板语言和.NET引擎,具有解析liquid模板的兼容模式 Github https://github.com/lunet-io/sc ...

  7. [jvm] -- 垃圾收集算法篇

    垃圾收集算法 标记-清除算法 首先标记出所有需要回收的对象,在标记完成后统一回收所有被标记的对象. 缺点: 效率问题: 空间问题(标记清除后会产生大量不连续的碎片) 复制算法 它可以将内存分为大小相同 ...

  8. Docker 入门教程(1)——安装

    docker大名听说了很久,一直没有去研究过,但现在面试动不动要求docker,还是研究下吧.由于我的电脑是win10系统(穷,买不起mac),安装过程各种坑爹问题不断,一度都想放弃,所以说垃圾win ...

  9. 一些非常实用的git命令

    阅读目录 一.前言 二.git branch 和 git checkout 三.git clone 和 git remote 四.git pull 和 git push 五.git merge 和 g ...

  10. ImportError: /lib64/libm.so.6: version `GLIBC_2.23' not found (required by /usr/local/python37/lib/python3.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)

    一 问题背景 这个错误的出现往往与我前面的一篇文章 ImportError: /lib64/libm.so.6: version `CXXAB_1.3.8.' not found (required ...