<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
button {
margin-top: 10px;
}
</style>
</head>
<body>
输入框:<input type="password" class="ipt"><br>
<button class="btn">眼睛图标</button>
<script>
var oIpt = document.querySelector('.ipt');
var oBtn = document.querySelector('.btn');
oBtn.onclick = function () {
if (oIpt.getAttribute('type') === 'password') {
oIpt.setAttribute('type', 'text');
console.log(111);
} else if (oIpt.getAttribute('type') === 'text') {
oIpt.setAttribute('type', 'password');
}
}
</script>
</body>
</html>