To hide the password input, you can set the 'type' attribute of the input element to 'password'. This will display dots or asterisks instead of the actual characters entered by the user.

Example:

<input type='password' name='password' id='passwordInput'>

To show the password input, you can change the 'type' attribute to 'text'.

Example:

<input type='text' name='password' id='passwordInput'>

You can use JavaScript to toggle between showing and hiding the password input based on user interaction. Here's an example using a button:

<input type='password' name='password' id='passwordInput'>
<button onclick='togglePasswordVisibility()'>Toggle Password Visibility</button>

<script>
function togglePasswordVisibility() {
  const passwordInput = document.getElementById('passwordInput');
  
if (passwordInput.type === 'password') {
    passwordInput.type = 'text';
  } else {
    passwordInput.type = 'password';
  }
}
</script>

This script will change the input type between 'password' and 'text' each time the button is clicked, allowing the user to show or hide the password.

How to Hide and Show Password Input in HTML

原文地址: https://www.cveoy.top/t/topic/qhTp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录