input에 비밀번호 확인 버튼 추가하기
우선, 비밀번호 보기 기능을 적용할 <input>을 <div class="password-container"></div>로 감싸 주세요.
그다음 </div>위 <input> 아래에 <i class="fa fa-lock" id="togglePassword"></i>를 추가해주세요.
*(완성된 모습, 기본 예시)
<div class="password-container">
<input type="password" required maxlength="20" placeholder="비밀번호">
<i class="fa fa-lock" id="togglePassword"></i>
</div>
그다음 아래의 코드를 페이지 원하는 곳에 아래의 코드를 입력해주세요.
<!--입력한 비밀번호 볼 수 있도록 구현{-->
<style>
.password-container {
position: relative;
}
#ol_pw {
width: 100%;
padding-right: 30px;
}
#togglePassword {
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
cursor: pointer;
}
</style>
<script>
// JavaScript
const togglePassword = document.querySelector('#togglePassword');
const password = document.querySelector('#ol_pw');
togglePassword.addEventListener('click', function () {
const type = password.getAttribute('type') === 'password' ? 'text' : 'password';
password.setAttribute('type', type);
if (type === 'text') {
togglePassword.classList.remove('fa-lock');
togglePassword.classList.add('fa-unlock-alt');
} else {
togglePassword.classList.remove('fa-unlock-alt');
togglePassword.classList.add('fa-lock');
}
});
</script>
<!--}비밀번호 보기 구현 끝-->
댓글 3개
감사합니다
감사합니다. ^^
좋은 정보 감사합니다.
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4420 | ||
| 2604 | 8개월 전 | 676 | ||
| 2603 | 8개월 전 | 735 | ||
| 2602 | 8개월 전 | 648 | ||
| 2601 |
|
8개월 전 | 671 | |
| 2600 |
|
8개월 전 | 580 | |
| 2599 | 8개월 전 | 809 | ||
| 2598 | 8개월 전 | 602 | ||
| 2597 |
다케미카코
|
8개월 전 | 756 | |
| 2596 | 8개월 전 | 854 | ||
| 2595 |
|
8개월 전 | 446 | |
| 2594 | 9개월 전 | 608 | ||
| 2593 |
만두먹고또먹고
|
9개월 전 | 938 | |
| 2592 | 9개월 전 | 613 | ||
| 2591 | 9개월 전 | 620 | ||
| 2590 | 9개월 전 | 689 | ||
| 2589 |
|
9개월 전 | 759 | |
| 2588 | 9개월 전 | 478 | ||
| 2587 | 9개월 전 | 796 | ||
| 2586 | 9개월 전 | 643 | ||
| 2585 | 9개월 전 | 511 | ||
| 2584 | 9개월 전 | 577 | ||
| 2583 | 9개월 전 | 498 | ||
| 2582 | 9개월 전 | 643 | ||
| 2581 | 9개월 전 | 598 | ||
| 2580 |
만두먹고또먹고
|
9개월 전 | 517 | |
| 2579 |
|
9개월 전 | 664 | |
| 2578 | 9개월 전 | 648 | ||
| 2577 | 9개월 전 | 627 | ||
| 2576 | 9개월 전 | 562 | ||
| 2575 |
이슈DEV
|
10개월 전 | 993 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기