css样式
<style>
.box{
position: relative;
}
.tu{
position: absolute;
top: 4px;
left: 270px;
width: 30px;
}
.int{
width: 300px;
height: 30px;
}
</style>
js
<script>
let _div = document.createElement('div');
let _input = document.createElement('input');
let _img = document.createElement('img');
_img.src='./img/eye.png';
document.body.appendChild(_div)
_div.appendChild(_input)
_div.appendChild(_img)
_div.setAttribute('class','box')
_input.setAttribute('class','int')
_img.setAttribute('class','tu')
let e = 0;
_img.onclick = function(){
e++
if(e%2 == 0){
_img.src = './img/eye.png'
_input.setAttribute('type','text')
} else {
_img.src = './img/lock.png'
_input.setAttribute('type','password')
}
}
</script>