html和js部分
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<header>
<div id="tou">
<label for="">ToDoList</label>
<input type="text" name="" id="inputBox" placeholder="请输入">
</div>
</header>
<section>
<h2>
正在进行
<span id="jxspan">0</span>
</h2>
<ul id="jinxing" class="xingjin">
<li id="jx">
<input type="checkbox">
<p id="content" class="">模板</p>
<button class="sc">删除</button>
</li>
</ul>
<h2>
已经完成
<span id="wcspan">0</span>
</h2>
<ul id="wancheng" class="chengwan">
</ul>
</section>
</body>
<script>
var _input = document.getElementById("inputBox");
var _p = document.getElementById("content");
var _jxul = document.getElementById("jinxing");
var _mbli = document.getElementById("jx");
var _jxspan = document.getElementById("jxspan");
var _wcspan = document.getElementById("wcspan");
var _wcul = document.getElementById("wancheng")
compute();
function compute() {
_jxspan.innerHTML = _jxul.children.length - 1;
_wcspan.innerHTML = _wcul.children.length;
}
_input.onkeypress = function (evt) {
var e = evt || event;
var key = e.keyCode || e.which || e.charCode;
if (key == 13 && _input.value != "") {
let newItem = _mbli.cloneNode(true);
let firstY = _jxul.firstElementChild;
_jxul.insertBefore(newItem, firstY);
newItem.id = "";
var _kuang = this.value;
newItem.querySelector("p").innerHTML = _kuang;
this.value = "";
compute();
}
var _shanchu = document.querySelectorAll("#jinxing .sc");
for (var i = 0; i < _shanchu.length; i++) {
_shanchu[i].onclick = function () {
this.parentElement.remove();
compute();
}
}
var _wcul = document.getElementById("wancheng")
var _fuk = document.querySelectorAll("#jinxing input");
for (var j = 0; j < _fuk.length; j++) {
_fuk[j].onclick = function () {
if (this.checked) {
_wcul.appendChild(this.parentElement);
compute();
} else {
_jxul.appendChild(this.parentElement);
compute();
}
}
}
}
</script>
</html>
css部分
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
li {
list-style: none;
}
header {
height: 50px;
background: #333;
background: rgba(47, 47, 47, 0.98);
}
#tou {
width: 600px;
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;
}
#tou 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;
text-rendering: auto;
color: -internal-light-dark(black, white);
text-shadow: none;
text-align: start;
cursor: text;
outline: none;
}
h2 {
width: 600px;
margin: 31px auto;
position: relative;
}
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;
}
ul {
width: 600px;
margin: 0 auto;
}
li {
width: 600px;
height: 32px;
background: #fff;
position: relative;
margin-bottom: 10px;
border-radius: 3px;
border-left: 5px solid #629A9C;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
display: flex;
justify-content: space-between;
align-items: center;
}
li input {
width: 22px;
height: 22px;
cursor: pointer;
margin-left: 10px;
}
p {
width: 502px;
height: 32px;
}
#wancheng li {
border-left: 5px solid #999;
opacity: 0.5;
}
#jx {
display: none;
}