-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1주차] 김다희 미션 제출합니다. #9
base: master
Are you sure you want to change the base?
Changes from 2 commits
edbe30a
fa25389
fb5f3e1
b1a254e
f42e8f8
9228c8a
b6c47e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,44 @@ | ||
//CEOS 19기 프론트엔드 파이팅🔥 ദ്ദി˶ˊᵕˋ˵) | ||
const inputField = document.querySelector('.todo-input'); //todo 입력창 | ||
const TodoButton = document.querySelector('.todo-input-button'); //+추가 버튼 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 변수만 카멜 케이스가 아니네요! |
||
const todoLists = document.querySelector('.todo-lists'); //todo list목록 | ||
const doneLists = document.querySelector('.done-lists'); //done list목록 | ||
|
||
|
||
TodoButton.addEventListener('click', addTodo); //+ 버튼 클릭시 todo에 list를 추가 | ||
|
||
function addTodo(event){ | ||
event.preventDefault(); //event에 대한 기본 동작 실행 방지 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. button에 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 헷갈렸던 부분인데 깔끔하게 정리해 주셔서 감사합니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그래서 저라면 div가 아니라 form 태그로 만들었을 거 같아요~! 버튼의 기본 type이 submit이라 그러면 인풋에 커서를 두고 enter를 치거나, 버튼을 click했을 때의 이벤트를 따로 처리해주지 않아도 form에 이벤트 핸들러를 submit으로 바로 붙여버리면 되거든요. 이때는 event.preventDefault()가 필요하겠죠? |
||
|
||
//todo list div 생성 | ||
const todoDiv = document.createElement("div"); | ||
todoDiv.classList.add("todo-div"); | ||
|
||
//todo list li 생성 | ||
const todoLi = document.createElement("li"); | ||
todoLi.classList.add("todo-li"); | ||
|
||
//todo list done button 생성 | ||
const doneButton = document.createElement('button'); | ||
doneButton.innerHTML = '<i class="fa-solid fa-circle-check" style="color: #28c840;"></i>'; | ||
doneButton.classList.add("done-button"); | ||
|
||
//todo list 삭제 button 생성 | ||
const deleteButton = document.createElement('button'); | ||
deleteButton.innerHTML = '<i class="fa-solid fa-square-minus" style="color: #ff5f58;"></i>' | ||
deleteButton.classList.add('delete-button'); | ||
|
||
//공백 여부에 따른 처리 | ||
if(!inputField.value.trim()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 공백여부 체크까지! 좋은거 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 공백여부 체크 너무 좋습니다~~ 사소하지만 공백여부를 함수 초기에 해주면 중간에 불필요한 요소를 만들어두지 않을 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 공백 여부 체크를 함수 상단에 두고, 빈 값일 경우 early return 처리 해준다면, 불필요한 노드 생성들을 막는데에 도움이 될 거 같아요~ 그리고 if문이 참일 때 실행하는 실행문에 중괄호가 생략되어있는데 추가되는게 좋을 거 같습니다! |
||
alert("할일을 추가해 보세요!"); | ||
else{ | ||
todoLi.innerText = inputField.value; | ||
todoDiv.appendChild(todoLi); | ||
todoDiv.appendChild(doneButton); | ||
todoDiv.appendChild(deleteButton); | ||
todoLists.appendChild(todoDiv); | ||
} | ||
|
||
//input field 초기화 | ||
inputField.value = ''; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
html에도 주석을 남기는 거 좋은거 같아요!