t

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>

<!--}비밀번호 보기 구현 끝-->

 

https://dsclub.kr/code/669

|

댓글 3개

감사합니다. ^^

좋은 정보 감사합니다.

댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

+
제목 글쓴이 날짜 조회
2년 전 조회 2,233
2년 전 조회 1,195
2년 전 조회 1,533
2년 전 조회 1,029
2년 전 조회 3,459
2년 전 조회 1,693
2년 전 조회 1,866
2년 전 조회 1,229
2년 전 조회 1,763
2년 전 조회 1,664
2년 전 조회 2,267
2년 전 조회 1,680
2년 전 조회 1,136
2년 전 조회 1,989
2년 전 조회 1,468
2년 전 조회 1,339
2년 전 조회 2,288
2년 전 조회 1,740
2년 전 조회 2,241
2년 전 조회 1,364
2년 전 조회 2,203
2년 전 조회 1,038
2년 전 조회 1,793
2년 전 조회 1,558
2년 전 조회 2,854
2년 전 조회 1,780
2년 전 조회 2,073
2년 전 조회 2,557
2년 전 조회 2,581
2년 전 조회 1,627