-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
63 lines (59 loc) · 2.1 KB
/
script.js
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
let myNodelist = document.getElementsByTagName("li");
for (let i = 0; i < myNodelist.length; i++) {
let span = document.createElement("span");
let txt = document.createTextNode("\u00D7"); //caracter x
span.className = "close";
span.appendChild(txt);
myNodelist[i].appendChild(span);
}
let close = document.getElementsByClassName("close");
for (let i = 0; i < close.length; i++) {
close[i].onclick = function () {
let div = this.parentElement;
div.style.display = "none";
}
}
let list = document.querySelector('ul');
list.addEventListener('click', function (ev) {
if (ev.target.tagName === 'LI') {
ev.target.classList.toggle('checked');
}
}, false);
function addElemento() {
let li = document.createElement("li");
let inputValue = document.getElementById("tarefa").value;
inputValue = inputValue.toUpperCase();
let dataAtual = new Date();
let dia = dataAtual.getDate();
let mes = dataAtual.getMonth() + 1; // Adicione +1 porque os meses são base 0 (janeiro = 0)
let ano = dataAtual.getFullYear();
let data = dia + "/" + mes + "/" + ano; // Formato: DD/MM/AAAA
let t = document.createTextNode(data + " - " + inputValue); // Adiciona data e texto
li.appendChild(t);
if (inputValue === '') {
alert("Você precisa descrever a tarefa");
} else {
document.getElementById("itemLista").appendChild(li);
}
document.getElementById("tarefa").value = "";
let span = document.createElement("SPAN");
let txt = document.createTextNode("\u00D7");
span.className = "close";
span.appendChild(txt);
li.appendChild(span);
for (let i = 0; i < close.length; i++) {
close[i].onclick = function () {
let div = this.parentElement;
div.style.display = "none";
}
}
}
function limparLista() {
let lista = document.getElementById("itemLista");
lista.innerHTML = ""; // Remove todos os elementos da lista
}
function adicionarComEnter(event) {
if (event.key === "Enter") {
addElemento();
}
}