Javascript Show/Hide toggle button for password field

后端 未结 6 1038
无人及你
无人及你 2021-01-22 18:24

I have been working on a project that requires me to implement a Show/Hide button on a form password field, that toggles between showing the password as plaintext, and hiding it

6条回答
  •  粉色の甜心
    2021-01-22 18:29

    function toggler(e) {
      if( e.innerHTML == 'Show' ) {
          e.innerHTML = 'Hide'
          document.getElementById('password').type="text";
      } else {
          e.innerHTML = 'Show'
          document.getElementById('password').type="password";
      }
    }
    
    

提交回复
热议问题