password show/hide
by alikong
HTML
<input autocomplete="false" type="password" id="key" />
<div id="keyShow">SHOW</div>
<button id="checkKey"> Submit </button>
<br />
비번을 입력을 시작하면 버튼이 나옵니다.
CSS
* {
font-family: arial;
}
*:focus {
outline: none;
}
body {
min-height: 130px;
font-size: 12px;
}
#key {
width: 200px;
margin: 10px 10px 10px 0;
border: 1px solid grey;
padding: 10px 40px 10px 10px;
}
#key:focus {
border-color: orange;
}
#keyShow {
position: absolute;
display: none;
margin-left: -50px;
margin-top: 24px;
font-size: 9px;
cursor: pointer;
color: grey;
}
#checkKey {
height: 39px;
}
JavaScript
$("#key").on("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
$("#checkKey").triggerHandler("click");
} else {
if (this.value) {
$("#keyShow").css("display", "inline-block");
} else {
$("#keyShow").hide();
}
}
}).focus();
$("#keyShow").on("click", function() {
if ($("#key").attr("type") == "password") {
$("#key").attr("type", "text");
$($(this)).text("H I D E");
} else {
$("#key").attr("type", "password");
$($(this)).text("SHOW");
}
});