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

자바스크립트 핵심

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

문제 2 : input 입력값 출력하기(value)
목록으로
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>문제2</title>

<style>

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

.wrap{
width:400px;
margin:100px auto;
text-align:center;
}

input{
width:100%;
height:50px;
padding:0 15px;
font-size:18px;
margin-bottom:20px;
}

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

h3{
margin-top:30px;
font-size:30px;
}

</style>
</head>
<body>

<div class="wrap">

<input type="text" class="text" placeholder="이름 입력">

<button>확인</button>

<h3></h3>

</div>

<script>

const inputEl = document.querySelector('.text');
const btnEl = document.querySelector('button');
const h3El = document.querySelector('h3');

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

const value = inputEl.value;

h3El.innerText = `${value}님 환영합니다`;

});

</script>

</body>
</html>
#문제 2 : input 입력값 출력하기(value)

첨부 파일

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

댓글 / 답글

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