-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
67 lines (42 loc) · 1.77 KB
/
index.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
64
65
66
67
'use strict';
const todoArray = []; //할 일들을 배열로 선언
let todoList = document.getElementById('todo__list').value;
let inputButton = document.querySelector('.input__button');
inputButton.addEventListener('click', addTodo);
// addEventListener(이벤트유형, 이벤트인터페이스를 구현할 "객체" 또는 "함수")
function addTodo(){
//input에 입력한 todo
const todo = document.querySelector('.todoItem').value;
if(todo === '' || todo === null){
alert('할일 리스트를 입력해주세요.');
document.querySelector('.todoItem').value = '';
document.querySelector('.todoItem').focus();
return;
}else if(todo !== '' || todo !== null){
alert('할일 리스트가 추가되었습니다.');
todoArray.push(todo);
document.querySelector('.todoItem').value ='';
document.querySelector('.todoItem').focus();
console.log(todo);
}
//리스트 보여주는 변수 생성
const li = document.createElement("li");
const deleteBtn=document.createElement('button');
// li.id ='test';
//할일 목록 추가 값
document.getElementById("todo__list").appendChild(li).innerText = todo;
//삭제 하기 버튼
li.appendChild(deleteBtn);
deleteBtn.textContent='제거하기';
deleteBtn.addEventListener('click', dleeteTodo)
// todoList.removeEventListener(li);
function dleeteTodo(event) {
const list = event.target.parentElement;
if(confirm('정말 삭제하시겠습니까?') === true){
list.remove();
}else{ //취소
return;
}
}
// addEventListener(이벤트유형, 이벤트인터페이스를 구현할 "객체" 또는 "함수")
} //addTodo 함수 끝