프런트엔드-자바스크립트

자바스크립트 핵심

강사: 정프런트 · 작성자: 이종춘 · 작성일: 2026-06-11 21:24:32 · 조회수: 17

문제 9 : 댓글 등록 기능
목록으로
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>문제9</title>

<style>
*{
margin:0;
padding:0;
box-sizing:border-box;
}

ul, li{
list-style:none;
}

.wrap{
width:400px;
margin:100px auto;
}

.input_wrap{
display:flex;
gap:10px;
}

input{
flex:1;
height:50px;
padding:0 15px;
font-size:18px;
}

button{
width:100px;
border:none;
background-color:tomato;
color:white;
font-size:18px;
cursor:pointer;
}

.comment_list{
margin-top:30px;
}

.comment_list li{
padding:15px;
background-color:#eee;
margin-bottom:10px;
border-radius:8px;
}
</style>
</head>

<body>

<div class="wrap">

<div class="input_wrap">
<input type="text" class="comment_input" placeholder="댓글 입력">
<button class="add_btn">등록</button>
</div>

<ul class="comment_list"></ul>

</div>

<script>

const inputEl = document.querySelector('.comment_input');
const addBtn = document.querySelector('.add_btn');
const listEl = document.querySelector('.comment_list');

addBtn.addEventListener('click', () => {

const value = inputEl.value;

const liEl = document.createElement('li');

liEl.innerText = value;

listEl.append(liEl);

inputEl.value = "";

});

</script>

</body>
</html>
#문제 9 : 댓글 등록 기능

첨부 파일

0개
첨부된 파일이 없습니다.

댓글 / 답글

0개
댓글을 작성하려면 로그인하세요.
아직 댓글이 없습니다.