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

자바스크립트 핵심

강사: 정프런트 · 작성자: 이종춘 · 작성일: 2026-05-26 18:52:40 · 조회수: 10

출석부 프로그램 설명
목록으로
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>출석부 프로그램</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f4f6f8;
padding: 40px;
}

.box {
width: 420px;
margin: 0 auto;
background: #fff;
padding: 30px;
border-radius: 16px;
box-shadow: 0 8px 25px rgba(0,0,0,0.1);
}

h1 {
text-align: center;
}

input {
width: 100%;
padding: 12px;
font-size: 16px;
margin-bottom: 10px;
box-sizing: border-box;
}

button {
width: 100%;
padding: 12px;
background: #2563eb;
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
cursor: pointer;
}

button:hover {
background: #1d4ed8;
}

ul {
margin-top: 20px;
padding-left: 20px;
}

li {
padding: 8px;
border-bottom: 1px solid #ddd;
}
</style>
</head>
<body>

<div class="box">
<h1>출석부 프로그램</h1>

<input type="text" id="studentName" placeholder="학생 이름 입력">
<button onclick="addStudent()">학생 추가</button>

<ul id="studentList"></ul>
</div>

<script>
let students = [];

function addStudent() {
let name = document.getElementById("studentName").value;

if (name === "") {
alert("학생 이름을 입력하세요.");
return;
}

students.push(name);

document.getElementById("studentName").value = "";

showStudents();
}

function showStudents() {
let html = "";

for (let i = 0; i < students.length; i++) {
html += "<li>" + students[i] + "</li>";
}

document.getElementById("studentList").innerHTML = html;
}
</script>

</body>
</html>
#출석부 프로그램

첨부 파일

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

댓글 / 답글

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