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

[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>

 

결과보기



분류 제목
js JS - with 키워드 - 객체 이용해 구문작성 (= with키워드 = 위드키워드)
js JS - 입력한 패스워드 확인 (보이기/숨기기) 토글 버튼 넣기
js JS - JavaScript로 (SlideUp/SlideDown) (FadeOut/FadeIn) 토글 버튼 …
js JS - 이미지 위에 마우스허버 시 툴팁창(Tooltip) 띄우기 ※ 클래스 속성값과 동일한 타이틀 속성 생…
js JS - 모든 링크 주소를 특정 URL주소로 일괄 변경
js JS - 화면 리사이즈 시, 스크롤바 가운데로 이동 (= 화면크기 변경 시, 스크롤바 중앙에 위치시키기)
js JS - 특정 문자열 글자 포함 요소의 글자색 스타일 변경
4/4
목록
찾아주셔서 감사합니다. Since 2012