-
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주차] 변지혜 미션 제출합니다. #10
base: master
Are you sure you want to change the base?
Changes from 1 commit
a24c871
b5d4888
3b1d31a
3404435
815e1f6
4b939a1
3b8d1c5
2ba446f
14ff3b9
aacdd1c
ac09578
3ad601d
f773b4e
912e0cf
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 초기화 함수 | ||
const form = document.querySelector(".todo-form"); | ||
|
||
const init = () => { | ||
form.addEventListener("submit", addTodoItem); | ||
}; | ||
|
||
// 할 일 추가 함수 | ||
const addTodoItem = () => { | ||
event.preventDefault(); | ||
// input에 입력한 value를 선택하여 todoContent에 대입 | ||
const todoContent = document.querySelector(".todo-input").value; | ||
if (todoContent) { | ||
printTodoItem(todoContent); | ||
} else { | ||
alert("할 일을 입력하세요!"); | ||
} | ||
}; | ||
|
||
// 입력 받은 할 일 출력 | ||
const printTodoItem = (text) => { | ||
const todoItem = document.createElement("li"); | ||
const todoText = document.createElement("span"); | ||
|
||
todoItem.className = "todo-list-item"; | ||
todoText.className = "todo-item-text"; | ||
todoText.innerText = text; | ||
|
||
// li에 item 추가 | ||
todoItem.appendChild(todoText); | ||
document.querySelector(".todo-list").appendChild(todoItem); | ||
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. 아래 현민님께서 잘 적어주셨는데, 코드 전체적으로 |
||
|
||
// input 창 초기화 | ||
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. printTodoItem 함수에서 한번 더 input 을 불러와서 value를 비워주는 것 보다는 addTodoItem 함수에서 이미 선언한 input이 있으므로 여기서 printTodoItem 을 호출한 후 value 비움 처리를 하는것이 더 효율적이지 않을까 생각합니다 ㅎㅎ |
||
document.querySelector(".todo-input").value = ""; | ||
}; | ||
|
||
// 시작 함수 | ||
init(); |
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.
이 부분에서
trim()
함수를 통해 공백 input에 대한 예외 handling이 있어도 좋을 것 같습니다