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. java上传组件commons-fileupload的一些使用方法

    在 http://www.apache.org,下载commons-fileupload-1.2.1.jar包,并把这个包加到工程中,以下是记录这个上传组件的一些使用方法. html测试页面,实现上传 ...

  2. 命令行开启WIFI

    netsh wlan set hostednetwork allow   //netsh wlan set hostednetwork mode=disallow netsh wlan set hos ...

  3. python学习记录(三)

    0827--https://www.cnblogs.com/fnng/archive/2013/02/24/2924283.html 通用序列操作 索引 序列中的所有元素都是有编号的--从0开始递增. ...

  4. spring mvc框架入门

    目录 1.web框架分层 2.什么是springmvc 3.springmvc的优势 4.springmvc和struct的区别 (spring mvc框架入门 1.web框架分层 一般web框架可以 ...

  5. 深入分析Java反射(三)-泛型

    前提 Java反射的API在JavaSE1.7的时候已经基本完善,但是本文编写的时候使用的是Oracle JDK11,因为JDK11对于sun包下的源码也上传了,可以直接通过IDE查看对应的源码和进行 ...

  6. Java程序员都需要懂的「反射」

    前言 只有光头才能变强. 文本已收录至我的GitHub精选文章,欢迎Star:https://github.com/ZhongFuCheng3y/3y 今天来简单写一下Java的反射.本来没打算写反射 ...

  7. 将STM32F407片外SRAM作运行内存

    本例演示用的软硬件: 片内外设驱动库:STM32CubeF41.24.1的HAL库1.7.6,2019年4月12日 IDE:MDK-ARM 5.28.0.0,2019年5月 开发板:片外SRAM挂在F ...

  8. Go语言实现:【剑指offer】跳台阶

    该题目来源于牛客网<剑指offer>专题. 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果). 1阶:共1种跳法: 2阶 ...

  9. Go语言实现:【剑指offer】二叉树中和为某一值的路径

    该题目来源于牛客网<剑指offer>专题. 输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路 ...

  10. drf路由分发、解析/渲染模块配置、使用admin、自动序列化配置

    目录 drf路由分发配置 解析模块配置 渲染模块配置 浏览器渲染打开 浏览器渲染关闭 结论 drf使用后台admin drf序列化模块 serializers.py: views.py:单查群查 测试 ...