-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
148 lines (127 loc) · 4.81 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<html>
<head>
<title>To-do list Website</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<style>
* {
box-sizing: border-box;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
width: 60%;
}
ul li {
border-radius: 12px;
border: 1px solid #ddd;
margin-top: -1px; /* Prevent double borders */
background-color: #dba6a6;
padding: 12px;
font-size: 18px;
color: black;
display: block;
position: relative;
}
ul li:hover {
background-color: rgb(219, 238, 113);
}
.xButton {
cursor: pointer;
position: absolute;
top: 50%;
right: 0%;
padding: 12px 16px;
transform: translate(0%, -50%);
}
.xButton:hover{
background: rgb(255, 255, 255);
}
.list{
font-size: larger;
}
h1{
width: 80%;
}
</style>
</head>
<body class="container-sm">
<h1 class="alert alert-primary" role="alert" style="text-align: center;">
Simple To-do web app
</h1>
<form >
<label for="toDoNext" class="form-label" >What to do?</label><br>
<div class="col-6">
<input type="text" class="form-control" id="toDoNext" name="todo" placeholder="What do you want to do?"><br>
</div>
<div class="row">
<div class="col-12">
<input type="button" class="btn btn-outline-primary" onclick="newElement()" name="submit" value="Let's do it">
</div>
</div>
<div>
<div class="row p-4">
<div class="col-2" >
<button onclick="commitChange()" type="button" class="btn btn-outline-danger" class="button">Commit Change</button>
</div>
<div class="col-2">
<button onclick="undoChange()" type="button" class="btn btn-outline-warning" class="button">Undo Change</button>
</div>
</div>
</div>
</form>
<ul id="unorderedList">
<li class = "list" >Chores</li>
<li class = "list">Homework</li>
</ul>
<script>
var xButtonClass = document.getElementsByClassName("xButton");
var clicked = [];
var listContent=document.getElementsByClassName("list")
function newElement() {
var list = document.getElementById("unorderedList");
var node = document.createElement("LI"); // Tạo một dòng mới trong một list
var xButton = document.createElement("SPAN"); // Tạo nút x ở trong thẻ span
var formValue = document.getElementById("toDoNext").value;
var textnode = document.createTextNode(formValue);
var clickYet;
node.className="list";
xButton.className = "xButton"; //Gán nút x là một nhãn nào đấy để tiện style
xButton.innerHTML = "×"; //Tạo nút x
node.appendChild(xButton);
node.appendChild(textnode);
list.appendChild(node);
xButton.addEventListener("click", function () {
clickYet=!clickYet;
if (clickYet==0) {
this.parentElement.style.textDecoration = 'none';
this.parentElement.style.backgroundColor= '#dba6a6';
}
else {
this.parentElement.style.textDecoration = 'line-through';
this.parentElement.style.backgroundColor= '#60e7b3';
}
console.log(this.parentElement.style.textDecoration);
});
}
function commitChange(){
var i;
for (i=1; i<listContent.length; i++){
if(listContent[i].style.textDecoration =='line-through'){
listContent[i].style.display='none';
}
}
}
function undoChange(){
var i;
for (i=1; i<listContent.length; i++){
if(listContent[i].style.display =='none'){
listContent[i].style.display='block';
//listContent[i].style.listStyle='round';
}
}
}
</script>
</body>
</html>