JS 模擬登陸框動態顯示密碼功能
阿新 • • 發佈:2019-02-17
執行成果如下,
程式碼如下,
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Dom物件</title> <script> window.onload=function(){ var display=document.getElementById("display"); display.onchange=function(){ var pwd=document.getElementById("pwd"); if(display.checked){ pwd.type="text"; }else{ //pwd.type="password"; pwd.setAttribute("type","password"); } } } </script> </head> <body> <form> 使用者名稱<input type="text" name="name" id="name"> <br> 密碼<input type="password" name="pwd" id="pwd" checked="true"> <br> <input type="checkbox" name="display" id="display">顯示密碼 </form> </body> </html>