<!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>
<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)