本文使用原生JS实现站点 http://www.todolist.cn/ 的基本功能。
其中页面的HTML布局和CSS样式取用原站,JS部分为自己编写。
效果图
完整代码
HTML、JS部分
<!DOCTYPE html>
<html>
<head>
<title>ToDoList—最简单的待办事项列表</title>
<link rel="stylesheet" href="todolist.css">
</head>
<body>
<header>
<section>
<form action="javascript: void(0)" id="form">
<label for="title">ToDoList</label>
<input type="text" id="title" placeholder="添加ToDo" autocomplete="off"/>
</form>
</section>
</header>
<section id="section">
<h2>正在进行 <span id="todocount"></span></h2>
<ol id="todolist" class="demo-box">
</ol>
<h2>已经完成 <span id="donecount"></span></h2>
<ul id="donelist">
</ul>
</section>
<script>
var title_ele = document.getElementById("title");
var todolist_ele = document.getElementById("todolist");
var donelist_ele = document.getElementById("donelist");
var section_ele = document.getElementById("section");
// 功能1,添加待办事项
addEvent(title_ele, "keydown", function(e){
var keyCode = e.which || e.keyCode;
var obj = {
tag_name : "li",
children : [
{
tag_name : "input",
attributes : {
type : "checkbox",
class : "checkbox"
}
},
{
tag_name : "p",
content : title_ele.value
},
{
tag_name : "a",
attributes : {
href : "javascript:void(0)"