Javascript Show/Hide toggle button for password field

后端 未结 6 1037
无人及你
无人及你 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:35

    Please make some changes.

    function text() {
    var a=document.getElementById('password');
    var b=document.getElementById('button');
    if (a.type=="password"){
    a.type = "text";
    b.innerText = "Hide";
    }
    else {
    a.type = "password";
    b.innerText = "Show";
    }
    }
    
    

提交回复
热议问题