• 회원가입
  • 로그인
  • 구글아이디로 로그인

[js] JS - 입력한 패스워드 확인 (보이기/숨기기) 토글 버튼 넣기

패스워드 확인 (보이기/숨기기) 토글 버튼

 

<style>

.pwdbox {

    position: relative;

    display: inline-block;

}


.pwdbox input[type="password"],

.pwdbox input[type="text"] {

    padding-right: 30px; /* 이미지 배치용 공간 확보. */

}


.password-toggle {

   position: absolute;

    top: 50%;

    right: 5px; /* 오른쪽 여백 조절 */

    transform: translateY(-50%);

    cursor: pointer;

}

</style>


<div class="pwdbox">

    <label for="pwd">Password:</label>

    <input type="password" id="pwd" name="pwd">

    <img src="https://i.imgur.com/YrkG5xB.gif" alt="Toggle Password" class="password-toggle" id="togglePwd">

</div>


<script>

const pwdInput = document.getElementById('pwd');

const togglePwd = document.getElementById('togglePwd');


togglePwd.addEventListener('click', function () {

    if (pwdInput.type === 'password') {

        pwdInput.type = 'text';

        togglePwd.src = 'https://i.imgur.com/YrkG5xB.gif'; 

    } else {

        pwdInput.type = 'password';

        togglePwd.src = 'https://i.imgur.com/PQNhCln.gif'; 

   }

});

</script>

 

결과보기


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
Basic JS - Home (JS입문) + Javascript Framework (프레임워크) 종류
Basic JS - Intro (JS소개)
Basic JS - Where To (JS위치) - JS구문 / JS코드위치 / JS사용법 ※ JS외부링크 주의사항
Basic JS - Output (JS출력= JS쓰기) ★★★★★
Basic JS - Syntax (JS구문) ★
Basic JS - Statement (JS구문= JS명령문)
Basic JS - Comment (JS주석)
Basic JS - Variable (JS변수) ★★★★★
Basic JS - Operator (연산자) - JS연산자 ★★★★★
Basic JS - Data Type - 데이터유형 ★★★★★ (= 데이터형식 = 데이터타입 = 데이터종류 = 자료형…
Basic JS - Function - JS함수 ★★★★★ ※ 일반함수 특징 2
Basic JS - Object - JS객체 ★★★★★
Basic JS - Scope - JS유효범위 (= JS접근범위 = 변수 종류) ★★★★★★★★★★
Basic JS - Event - JS이벤트 (= JS코드실행방법) ★★★★★
Basic JS - Strings - JS문자열
Basic JS - String Methods - JS문자열메서드
Basic JS - Number - JS숫자
Basic JS - Number Method - JS숫자메서드
Basic JS - Math 객체 - JS수학객체 (= JS산수객체 = Math객체 = Math Object = 매스 …
Basic JS - Dates - JS날짜
1/67
목록
찾아주셔서 감사합니다. Since 2012