JavaScript

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

 

결과보기



분류 제목
DOM_Style JS - textJustify -
DOM_Style JS - textOverflow 속성 - 영역 벗어난 글자 처리 (= 영역이탈글자처리 = 텍스트오버플로속성 …
DOM_Style JS - textShadow 속성 - 글자그림자 (= text-shadow속성 = 글자음영 = 텍스트섀도, …
DOM_Style JS - textTransform 속성 - 텍스트 대소문자변환 (= textTransform속성 = 텍스트트…
DOM_Style JS - top -
DOM_Style JS - transform -
DOM_Style JS - transformOrigin -
DOM_Style JS - transformStyle -
DOM_Style JS - transition -
DOM_Style JS - transitionProperty -
DOM_Style JS - transitionDuration -
DOM_Style JS - transitionTimingFunction -
DOM_Style JS - transitionDelay -
DOM_Style JS - unicodeBidi 속성 - 텍스트글자방향 (= unicodeBidi속성 = 유니코드비디속성)
DOM_Style JS - userSelect -
67/89
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티
웹유틸
회원센터
홈짱닷컴 PC버전 로그인