这是我第一次在 Stack Overflow 上提问,如果我弄乱了格式,请原谅我。我正在尝试用 class=accessGranted CSS 替换输入密码框。当用户在输入框中键入内容并按下回车键时,它应该用 CSS .accessGranted 替换输入框。
它应该用绿色字母的 ACCESS GRANTED 替换输入密码框。此外,我无法弄清楚如何摆脱自动显示在页面上的 ACCESS GRANTED。 JSFiddle 链接将告诉您我在说什么。
HTML:
<body>
<input class="passwordPress" type="password" />
<div class="accessGranted"></div>
</body>
CSS:
.accessGranted:before {
font-size: 20px;
color: #4eff73;
font: sans serif;
margin-top: 200px;
margin-left: 200px;
display: block;
content: "ACCESS GRANTED";
}
body {
background-color: #000;
}
.passwordPress {
margin-top: 200px;
margin-left: 200px;
}
JQuery:
$('.passwordPress').bind("enterKey",function(e){
alert("Enter");
});
$('.passwordPress').keypress(function(e){
if(e.keyCode == 13)
{
$(this).replaceWith('<div class="accessGranted"></div>');
}
});
这是 JSFiddle 的链接:http://jsfiddle.net/x7HVQ/606/
最佳答案
How to get rid of the ACCESS GRANTED that automatically shows up on the page:
只需删除 <div>
在 html
正文
<body>
<input class="passwordPress" type="password" />
<!--<div class="accessGranted"></div> -->
</body>
关于javascript - 如何用充满 CSS 的 <div> 替换 <input text box>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23796128/