답변 1개
채택된 답변
+20 포인트
1년 전
※ CSS, JavaScript 코드를 사용한 HTML로 만들 수 있을 것입니다.
>>> 만들어진 HTML을 브라우저로 열면 숫자를 한 자리씩 입력할 수 있고,
모든 입력이 완료되면 "확인" 버튼이 활성화되는 폼이 생성 됩니다.
mark_up.html
Copy
Verification Input
.verification-input {
display: flex;
gap: 10px;
}
.code-input {
width: 40px;
height: 40px;
font-size: 24px;
text-align: center;
}
button {
margin-top: 20px;
padding: 10px 20px;
font-size: 18px;
cursor: not-allowed;
}
button:enabled {
cursor: pointer;
background-color: #4CAF50;
color: white;
}
확인
const inputs = document.querySelectorAll(".code-input");
inputs.forEach((input, index) => {
input.addEventListener("input", (event) => {
if (event.target.value.length === 1 && index inputs.length - 1) {
inputs[index + 1].focus();
}
checkFilledInputs();
});
input.addEventListener("keydown", (event) => {
if (event.key === "Backspace" && input.value.length === 0 && index > 0) {
inputs[index - 1].focus();
}
});
});
function checkFilledInputs() {
const allFilled = [...inputs].every(input => input.value.length === 1);
document.getElementById("submit").disabled = !allFilled;
}
>>> 브라우저의 요청을 받으면 숫자를 한 자리씩 입력할 수 있고,
모든 입력이 완료되면 [확인] 버튼이 활성화되는 폼이 열립니다.
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인