<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.box {
position: relative;
height: 40px;
width: 300px;
border: 1px solid black;
}
.box input {
width: 200px;
/*height:40px;*/
border: 0;
outline: none;
}
img {
position: absolute;
top: 2px;
right: 2px;
width: 24px;
height: 24px;
}
</style>
</head>
<body>
<div class='box'>
<input type="password" value=''>
<img src="./img/close.png" alt="">
</div>
<script>
var flag = 1;
var Oipt = document.querySelector('input');
var Oimg = document.querySelector('img');
Oimg.onclick = function() {
if (flag === 1) {
Oimg.src = './img/open.png';
//修改标签的属性
Oipt.type = 'text'
flag = 0
} else {
Oimg.src = './img/close.png';
//修改标签的属性
Oipt.type = 'password'
flag = 1
}
}
</script>
</body>
</html>
JavaScript账号密码输入框
最新推荐文章于 2023-11-23 13:04:56 发布