demo ‘todolist’项目开发
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): 识别项目开发中的ProtoType、Demo、MVP
软件开发是很分裂的,只有不断使用原则和规律,才能带来质量. 只要不是玩具性质的项目,项目应该可以大概划分为0-1,1-10,10-100,100-1000四个种重要阶段.其中,0-1是原型验证性的:1 ...
- demo项目开发(Python+flask+mysql+redis只包含后端接口)
[demo项目开发需求] 用户信息管理,可以注册.登录.添加用户.删除用户 注册:任何用户可以注册,对用户提交的注册信息进行校验,返回对应的信息,其中: 用户名:必填,唯一 密码:必填,只能6-12位 ...
- 开发“todolist“”项目及其自己的感悟
一,项目题目: 实现“todolist项目” 该项目主要可以练习js操控dom事件,事件触发之间的逻辑关系,以及如何写入缓存,获取缓存.固定. 二,todolist简介 ToDoList是一款非常优秀 ...
- Jquery开发&BootStrap 实现“todolist项目”
作业题目:实现“todolist项目” 作业需求: 基础需求:85%参考链接http://www.todolist.cn/1. 将用户输入添加至待办项2. 可以对todolist进行分类(待办项和已完 ...
- TODOList项目
[ 爱上Swift]十二期:TODOList项目 好久没有写Swift甚是想念,Swift,Xcode都比较稳定了写个程序熟悉一下,当然时间原因都是小Demo,废话不多说先上图. 下面是跑起来之后 ...
- HTML+CSS项目开发总结
好几天没更新博客了,刚实战完一个HTML+CSS的简单项目.经过几天的摸索,发现收益良多.之前只是单纯得写demo,看知识点,没有亲自实战项目.但实战过后才会了解,如何才能更好地提升自己的技术.针对这 ...
- 用vuejs实现一个todolist项目
用vue.js实现一个todolist项目:input输入框输入的值会呈现在下方,并且会保存在localStorage里面,而且下方的列表点击之后也会有变化: 完整代码: App.vue <te ...
- [转]基于Starling移动项目开发准备工作
最近自己趁业余时间做的flash小游戏已经开发得差不多了,准备再完善下ui及数值后,投放到国外flash游戏站.期间也萌生想法,想把游戏拓展到手机平台.这两天尝试了下,除去要接入ane接口的工作,小游 ...
- 使用MyEclipse搭建java Web项目开发
转自:http://blog.csdn.net/jiuqiyuliang/article/details/36875217 首先,在开始搭建MyEclipse的开发环境之前,还有三步工具的安装需要完成 ...
随机推荐
- pyspark 记录
import os import sys spark_name = os.environ.get('SPARK_HOME',None) if not spark_name: raise ValueEr ...
- CCF_201509-1_数列分段
水. #include<iostream> #include<cstdio> using namespace std; int main() { ]; cin >> ...
- java一些技术
怎么样得到编译.java文件得到.class文件 两个用于反编译的工具Luyten和java decompiler 直接将jar包或则.class字节码文件拖到里面即可得到反汇编得到对应的java文件 ...
- 真正解决百度编辑器UEditor上传图片跨域问题
做前后端分离的项目用到UEditor,把上传图片程序拿出来放到了接口程序中,上传图片接口已经做了跨域处理,按理说编辑器中上传图片应该不会有问题.可是配置好图片上传路径后,运行,打开调试,测试一下,报错 ...
- 题解 SP1716 【GSS3 - Can you answer these queries III】
\[ Preface \] 没有 Preface. \[ Description \] 维护一个长度为 \(n\) 的数列 \(A\) ,需要支持以下操作: 0 x y 将 \(A_x\) 改为 \( ...
- 深入JVM垃圾回收机制,值得你收藏
JVM可以说是为了Java开发人员屏蔽了很多复杂性,让Java开发的变的更加简单,让开发人员更加关注业务而不必关心底层技术细节,这些复杂性包括内存管理,垃圾回收,跨平台等,今天我们主要看看JVM的垃圾 ...
- 《C# 爬虫 破境之道》:第二境 爬虫应用 — 第六节:反爬策略研究
之前的章节也略有提及反爬策略,本节,我们就来系统的对反爬.反反爬的种种,做一个了结. 从防盗链说起: 自从论坛兴起的时候,网上就有很多人会在论坛里发布一些很棒的文章,与当下流行的“点赞”“分享”一样, ...
- pytorch --Rnn语言模型(LSTM,BiLSTM) -- 《Recurrent neural network based language model》
论文通过实现RNN来完成了文本分类. 论文地址:88888888 模型结构图: 原理自行参考论文,code and comment: # -*- coding: utf-8 -*- # @time : ...
- ELK 记录 java log4j 类型日志
ELK 记载 java log4j 时,一个报错会生成很多行,阅读起来很不方便. 类似这样 解决这个问题的方法 1.使用多行合并 合并多行数据(Multiline) 有些时候,应用程序调试日志会包含 ...
- Fastdfs php扩展访问
一.安装FastDFS client php extension compiled under PHP 5.4 and PHP 7.0 1.安装php扩展,进入fastdfs源码文件夹中的 ph ...