<!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>passWordPlus</title>
<style>
input,img,p{
margin: 0px;padding: 0px;
}
div{
display: inline-block;
position: relative;
}
p{
display: inline-block;
position: relative;
left: 15px;
font-size: 5px;
}
img{
width: 27px;
display:none;
}
.iconChange{
display: block;
position: absolute;
left: -5px;
bottom:-2px;
}
</style>
</head>
<body>
<input id="passWord" type="password">
<div>
<img src="" > <!--行內權重比較大 不能放行內-->
<p>密碼需6~16位</p>
</div>
<script>
var input = document.getElementById("passWord")
var icon = document.querySelector('img')
var hint = document.querySelector("p")
input.onblur=function(){
if(input.value.length<6 || input.value.length>16){
hint.innerHTML="**請注意***密碼需6~16位";
icon.className="iconChange"
icon.src="img/x.png";
}else{
hint.textContent=""
icon.className="iconChange"
icon.src="img/v.jpg"
}
}
</script>
</body>
</html>