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 - perspective -
DOM_Style JS - perspectiveOrigin -
DOM_Style JS - position 속성 - 위치기준대상지정 (= 위치속성 = 포지션속성 = position속성, 상속…
DOM_Style JS - quotes -
DOM_Style JS - resize 속성 - 사용자의 요소크기 조정가능여부 지정 (IE는 지원 X)
DOM_Style JS - right -
DOM_Style JS - tableLayout 속성 - 테이블 셀, 행 및 열을 레이아웃 (= table-layout속성 =…
DOM_Style JS - tabSize -
DOM_Style JS - textAlign 속성 ★ - 텍스트 가로/수평 정렬 (= 텍스트 좌측정렬/중앙정렬/우측정렬 = 텍…
DOM_Style JS - textAlignLast -
DOM_Style JS - textDecoration -
DOM_Style JS - textDecorationColor 속성 - 텍스트라인색깔 (= 텍스트데커레이션컬러속성, IE지원X…
DOM_Style JS - textDecorationLine 속성 - 텍스트라인위치 (윗줄,밑줄 등..) (= 텍스트데커레이션…
DOM_Style JS - textDecorationStyle 속성 - 텍스트라인모양 (굵은선, 파선, 점선, 물결선 등) (…
DOM_Style JS - textIndent 속성 - 텍스트 들여쓰기/내어쓰기 (= textIndent속성 = 텍스트인덴트속…
66/89
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티 2
웹유틸
회원센터
홈짱닷컴 PC버전 로그인