todolist-site-----------主文件夹
  css------------css文件文件夹
    header.css---主页面头部样式css
section.css---主页面内容样式css
footer.css---主页面尾部样式css
    reset.css---清除默认样式css
  js-------------js文件文件夹
    index.js---js脚本文件
  index.html-----启动程序

本项目参考了http://www.todolist.cn/点击打开链接,对代码进行了一些精简,并添加了一些功能。在实现项目的过程中,首先是实现最基本的功能,然后不断地添加增强功能和美化。

1
2
3
4
5
6
7
8
9
参考链接http://www.todolist.cn/
 
1.将用户输入添加至待办项
 
2.可以对todolist进行分类(待办项和已完成组),用户勾选既将待办项分入已完成组
 
3.todolist的每一项可删除和编辑
 
4.下方有clear按钮,并清空所有todolist项

  

header.css

 /*背景*/
body{
background-color: #cdcdcd;
font-size: 16px;
}
/*头部*/
.header{
height: 50px;
background-color: #333;
}
.header .section h3{
float: left;
color: #ddd;
font-size: 24px;
line-height: 50px;
}
.header .section input{
float: right;
width: 60%;
height: 24px;
margin-top: 12px;
text-indent: 10px;
border-radius: 5px;
border: none;
}
.header .section button{
float: right;
width: 35px;
height: 24px;
margin-top: 12px;
border-radius: 5px;
border: none;
text-indent:10px 10px;
text-align: center;
}

section.css

 .section{
width: 600px;
padding: 0 10px;
margin: 0 auto;
overflow:hidden;
}
.section h2{
position: relative;
display: block;
width: 100%;
font-size: 24px;
line-height: 30px;
margin-block-start: 0.83em;
margin-block-end: 0.83em;
font-weight: bold;
text-align: left
}
.section h2 span{
position: absolute;
top: 13px;
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;
}
.section ul{
list-style: none;
}
.section ul 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);
}
.section ul li>input{
position: absolute;
top: 6px;
left: 10px;
width: 22px;
height: 22px;
cursor: pointer;
}
.section ul li a{
position: absolute;
top: 2px;
right: 5px;
display: inline-block;
width: 14px;
height: 12px;
border-radius: 14px;
border: 6px double #FFF;
background: #CCC;
line-height: 14px;
text-align: center;
color: #FFF;
font-weight: bold;
font-size: 14px;
cursor: pointer;
}
.section #donelist li{
opacity: 0.5;
}

footer.css

 .footer {
color: #666;
font-size: 15px;
text-align: center;
}
.footer a{
color: #666;
text-decoration: none;
color: #999;
}

reset.css

/*百度*/
body{
font-family:arial,helvetica,sans-serif;
font-size:13px;
font-size-adjust:none;
font-stretch:normal;
font-style:normal;
font-variant:normal;
font-weight:normal;
line-height:1.4;
text-align:center;
}
body, ul, ol, dl, dd, h1, h2, h3, h4, h5, h6, p, form, fieldset, legend, input, textarea, select, button, th, td {
margin:0;
padding:0;
}
h1, h2, h3, h4, h5, h6 {
font-size:100%;
font-weight:normal;
}
table {
font-size:inherit;
}
input, select {
font-family:arial,helvetica,clean,sans-serif;
font-size:100%;
font-size-adjust:none;
font-stretch:normal;
font-style:normal;
font-variant:normal;
font-weight:normal;
line-height:normal;
}
button {
overflow:visible;
}
th, em, strong, b, address, cite {
font-style:normal;
font-weight:normal;
}
li {
list-style-image:none;
list-style-position:outside;
list-style-type:none;
}
img, fieldset {
border:0 none;
}
ins {
text-decoration:none;
}

  index.js

 var todolist = $('todolist');
var donelist = $('donelist');
var todoCount = $('todocount');
var doneCount = $('donecount');
var todoc =0;
var donec=0;
//添加todolist
function postaction(){
//获取用户输入内容
var contant = $('searchinput').value;
//判断
if(contant.length === 0){
alert('请输入内容');
return;
}
//创建li标签插入
var newli = document.createElement('li');
newli.innerHTML ="<input type='checkbox' onchange ='update()'>"+"<p onclick='edit()'>"+ contant+ "</p>" + "<a herf = 'javescript:void(0)'>-</a>";
$('todolist').insertBefore(newli,$('todolist').children[0]);
loop('todolist');
todoc++;
todoCount.innerText = todoc;
//清空输入框的内容
$('searchinput').value = '';
}
// 循环每次添加不同的i值
function loop(str){
var list = null;
str ==='todolist' ? list = todolist :list =donelist; childs = list.childNodes;
for(var i=0; i<childs.length;i++){
childs[i].children[0].setAttribute('onchange','update("'+i+'","'+str+'")');
childs[i].children[1].setAttribute('onclick','edit("'+i+'","'+str+'")');
childs[i].children[1].setAttribute('onchange','change("'+i+'","'+str+'")');
childs[i].children[2].setAttribute('href','javascript:remove("'+i+'","'+str+'")');
}
}
//update方法
function update(n,str){
var list = null;
str === 'todolist' ? list = todolist : list = donelist; var li = null;
childs = list.childNodes;
for(var i=0;i<childs.length;i++){
if(i===Number(n)){
li = childs[i];
}
}
// 删除原有的,得到li 并刷新了原有的li
remove(n,str); if(str==='todolist'){
if(donec ===0){
donelist.appendChild(li);
}else {
donelist.insertBefore(li,donelist.children[0]);
}
loop('donelist');
donec++;
doneCount.innerText = donec;
}else if(str ==='donelist'){
todolist.appendChild(li);
loop('todolist');
todoc++;
todoCount.innerText = todoc;
}
}
//修改span
function edit(n,str){
var list = null;
str ==='todolist' ? list = todolist : list = donelist;
childs = list.childNodes;
p = childs[n].children[1];
title = p.innerHTML; p.innerHTML="<input id='input-"+ n +"' value='"+title+"' />";
var input = $("input-"+n);
input.setSelectionRange(0,input.value.length);
input.focus();
}
//修改input成p标签
function change(n,str){
var list = null;
str ==='todolist' ? list = todolist : list = donelist;
childs = list.childNodes;
p = childs[n].children[1];
title = p.children[0].value;
if(title.length === 0){
alert("内容不能为空");
}
else{
p.innerHTML = title;
}
}
//删除一个li
function remove(n,str){
var list=null;
if (str==='todolist'){
list = todolist;
todoc--;
todoCount.innerText = todoc;
} else if(str==='donelist'){
list = donelist;
donec--;
doneCount.innerText = donec;
} childs = list.childNodes;
for(var i=childs.length-1;i>=0;i--){
if(i===Number(n)){
list.removeChild(childs[n]);
}
}
loop(str);
}
//删除全部li
function clear(){
childs1 = todolist.childNodes;
for(var i=childs1.length-1;i>=0;i--){
todolist.removeChild(childs1[i]);
}
childs2 = donelist.childNodes;
for(var j=childs2.length-1;j>=0;j--){
donelist.removeChild(childs2[j]);
}
todoc = 0;
donec = 0;
todoCount.innerText = todoc;
doneCount.innerText = donec;
}
//根据id获取
function $(id){
return typeof id === 'string' ? document.getElementById(id) : null;
}
 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>todolist</title>
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/header.css">
<link rel="stylesheet" type="text/css" href="css/section.css">
<link rel="stylesheet" type="text/css" href="css/footer.css">
</head>
<body>
<div class="header">
<div class="section">
<h3>ToDolist</h3>
<input type="text" name="title" placeholder="添加ToDo" id="searchinput">
<button id="btn" onclick="postaction()">添加</button>
</div>
</div>
<div class="section">
<h2>
正在进行
<span id="todocount">0</span>
</h2>
<ul id="todolist"></ul>
<h2>
已经完成
<span id="donecount">0</span>
</h2>
<ul id="donelist"></ul>
</div>
<div class="footer"> Copyright © 2019 todolist.cn
<a href="javascript:clear();">clear</a>
</div>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>

demo ‘todolist’项目开发的更多相关文章

  1. 炼金术(1): 识别项目开发中的ProtoType、Demo、MVP

    软件开发是很分裂的,只有不断使用原则和规律,才能带来质量. 只要不是玩具性质的项目,项目应该可以大概划分为0-1,1-10,10-100,100-1000四个种重要阶段.其中,0-1是原型验证性的:1 ...

  2. demo项目开发(Python+flask+mysql+redis只包含后端接口)

    [demo项目开发需求] 用户信息管理,可以注册.登录.添加用户.删除用户 注册:任何用户可以注册,对用户提交的注册信息进行校验,返回对应的信息,其中: 用户名:必填,唯一 密码:必填,只能6-12位 ...

  3. 开发“todolist“”项目及其自己的感悟

    一,项目题目: 实现“todolist项目” 该项目主要可以练习js操控dom事件,事件触发之间的逻辑关系,以及如何写入缓存,获取缓存.固定. 二,todolist简介 ToDoList是一款非常优秀 ...

  4. Jquery开发&BootStrap 实现“todolist项目”

    作业题目:实现“todolist项目” 作业需求: 基础需求:85%参考链接http://www.todolist.cn/1. 将用户输入添加至待办项2. 可以对todolist进行分类(待办项和已完 ...

  5. TODOList项目

    [ 爱上Swift]十二期:TODOList项目   好久没有写Swift甚是想念,Swift,Xcode都比较稳定了写个程序熟悉一下,当然时间原因都是小Demo,废话不多说先上图. 下面是跑起来之后 ...

  6. HTML+CSS项目开发总结

    好几天没更新博客了,刚实战完一个HTML+CSS的简单项目.经过几天的摸索,发现收益良多.之前只是单纯得写demo,看知识点,没有亲自实战项目.但实战过后才会了解,如何才能更好地提升自己的技术.针对这 ...

  7. 用vuejs实现一个todolist项目

    用vue.js实现一个todolist项目:input输入框输入的值会呈现在下方,并且会保存在localStorage里面,而且下方的列表点击之后也会有变化: 完整代码: App.vue <te ...

  8. [转]基于Starling移动项目开发准备工作

    最近自己趁业余时间做的flash小游戏已经开发得差不多了,准备再完善下ui及数值后,投放到国外flash游戏站.期间也萌生想法,想把游戏拓展到手机平台.这两天尝试了下,除去要接入ane接口的工作,小游 ...

  9. 使用MyEclipse搭建java Web项目开发

    转自:http://blog.csdn.net/jiuqiyuliang/article/details/36875217 首先,在开始搭建MyEclipse的开发环境之前,还有三步工具的安装需要完成 ...

随机推荐

  1. 一个支持 CodeFirst/DbFirst/ModelFirst 的数据库小工具

    一个支持 CodeFirst/DbFirst/ModelFirst 的数据库小工具 Intro DbTool 是一个支持 CodeFirst/DbFirst/ModelFirst 的数据库小工具,原本 ...

  2. Jenkins report 打开样式失败解决方案

    1.临时解决方案(重启Jenkins失效):在系统管理->脚本命令行: 执行: System.setProperty("hudson.model.DirectoryBrowserSup ...

  3. thinkphp远程执行漏洞的本地复现

    thinkphp远程执行漏洞的本地复现 0X00漏洞简介 由于ThinkPHP5 框架控制器名 没有进行足够的安全监测,导致在没有开启强制路由的情况下,可以伪装特定的请求可以直接Getshell(可以 ...

  4. [redis读书笔记] 第二部分 集群

    1. 一个集群会包含多个节点(一个节点就是一个reid是服务器),CLUST MEET <ip><port>可以添加一个node到集群,命令执行后,两个node之间就会进行握手 ...

  5. Shell脚本 一键重启

    有个程序必须用 kill -9 pid号   关闭后,才能重新启动,每次都要手动查找pid号,麻烦容易出错,写个shell脚本 就三行很方便,自动查找pid号-关闭程序-重启程序 #!/bin/bas ...

  6. Linux文本界面字体颜色修改

    环境 基于centos 6.5 在文本界面 系统目录的字体颜色是 黑底蓝字  严重看不清楚,对此作出修改 使用 vi 编辑   进入  /etc/DIR_COLORS 找到“DIR 01;34   # ...

  7. ps查看资源消耗

  8. vue路由--动态路由

    前面介绍的路由都是路径和组件一对一映射的 有时候需要多个路径映射到一个组件,这个组件根据参数的不同动态改变,这时候需要用到动态路由 动态路由这样定义路由路径: path: '/foo/:id'--可以 ...

  9. 用c语言实现简单的五子棋

    用c语言实现简单的五子棋 这个小游戏是从零开始的实现的,框架灵感来自于小游戏<走迷宫>. 游戏代码配置: 二维数组+简单逻辑+getch读取键盘+windows函数(刷屏,改颜色,改窗口大 ...

  10. BIO&NIO

    在BIO中只有一个核心对象--Stream,它是单向的数据传输通道,即每个Stream要么是输入要么是输出的,不可兼得.开发人员是面向Stream进行编程的. 在NIO中有三个核心对象--Seleto ...