<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="password" id="password" />
<button id="show">显示/隐藏密码</button>
</body>
<script>
{
let show = document.querySelector('#show');
let password = document.querySelector('#password')
show.onclick = () => {
if(password.getAttribute('type') !== 'text'){
password.setAttribute('type','text')
}else{
password.setAttribute('type','password')
}
}
}
</script>
</html>