在填写表单时,会出现这样一种情况:我们键入密码,并希望查看到目前为止键入的内容。要看到这一点,有一个复选框点击,使字符可见。 在本文中,这个功能(即切换密码)是使用JavaScript实现的。
null
算法 1) 创建一个HTML表单,其中包含密码类型的输入字段。
2) 创建一个负责切换的复选框。
3) 创建一个函数,当用户点击复选框时,该函数将响应切换。
例如:
密码是Geeksforgeks。 所以,在输入时,它会显示如下 ************* 单击该复选框将显示以下字符: 极客 .
<!DOCTYPE html> <html> <body> <b><p>Click on the checkbox to show or hide password: </p></b> <b>Password</b>: <input type= "password" value= "geeksforgeeks" id= "typepass" > <input type= "checkbox" onclick= "Toggle()" > <b>Show Password</b> <script> // Change the type of input to password or text function Toggle() { var temp = document.getElementById( "typepass" ); if (temp.type === "password" ) { temp.type = "text" ; } else { temp.type = "password" ; } } </script> </body> </html> |
输出:
- 隐藏密码:
- 显示密码:
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END