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

자바스크립트 핵심

강사: 정프런트 · 작성자: 이종춘 · 작성일: 2026-05-26 18:54:08 · 조회수: 8

출석부 삭제 프로그램 설명
목록으로
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>출석부 삭제 프로그램</title>

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

body{
background:#f4f6f8;
font-family:Arial, sans-serif;
padding:50px;
}

.wrap{
width:500px;
background:white;
margin:auto;
padding:30px;
border-radius:20px;
box-shadow:0 10px 30px rgba(0,0,0,0.1);
}

h1{
text-align:center;
margin-bottom:20px;
}

input{
width:100%;
padding:12px;
margin-bottom:10px;
border:1px solid #ddd;
border-radius:10px;
font-size:16px;
}

button{
padding:12px 20px;
border:none;
border-radius:10px;
background:#2563eb;
color:white;
cursor:pointer;
font-size:16px;
margin-bottom:10px;
}

button:hover{
background:#1d4ed8;
}

ul{
margin-top:20px;
}

li{
list-style:none;
background:#eee;
padding:15px;
margin-bottom:10px;
border-radius:10px;

display:flex;
justify-content:space-between;
align-items:center;
}

.deleteBtn{
background:red;
padding:8px 12px;
border-radius:8px;
color:white;
cursor:pointer;
}
</style>

</head>
<body>

<div class="wrap">

<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]}

<button
class="deleteBtn"
onclick="deleteStudent(${i})">
삭제
</button>
</li>
`;
}

document.getElementById("studentList")
.innerHTML = html;
}


// 학생 삭제
function deleteStudent(index){

students.splice(index, 1);

showStudents();
}

</script>

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

첨부 파일

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

댓글 / 답글

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