Senha e Password Div
by thvinic
HTML
<input type="text" id="password">
<br>
<input id="button" type="button" value="Login">
<div id="HIDDENDIV" class="hidden">bla</div>
<div id="container">
<a id="foo" href="javascript:void(0);">Click Me</a>
<div class="conteudo1" id="bar">xxxxxx</div>
</div>
CSS
ofusque este css
#container {
width:200px;
height:220px;
}
#foo {
display:block;
float:left;
width:200px;
height:20px;
text-align:center;
}
#bar {
display:none;
float:left;
height:200px;
width:200px;
background:#000000;
}
JavaScript
$(document).ready(function () {
$('#foo').click(function () {
$(this).siblings().toggle();
//you need to pass string values, your variables display & block was not defined
localStorage.setItem('display', $(this).siblings().is(':visible'));
});
var block = localStorage.getItem('display');
if (block == 'true') {
$('#bar').show()
}
});
// Get references to the elements you'll be working with
var input = document.getElementById("password");
var div = document.getElementById("HIDDENDIV");
var btn = document.getElementById("button");
// Set up event handlers in JavaScript
button.addEventListener("click", validate);
function validate(){
if (input.value == '123') {
// No need to add a "show" class. Just remove the "hidden" class.
div.classList.remove('hidden');
// Or, add it:
input.classList.add("hidden");
$(this).siblings().toggle();
//you need to pass string values, your variables display & block was not defined
localStorage.setItem('display', $(this).siblings().is(':visible'));
var block = localStorage.getItem('display');
if (block == 'true') {
$('#bar').show()
}
if ($("#bar:visible").length) {
// it's visible
} else {
alert("Janela Acendeu!");
}
} else {
password.focus(); // <-- If you don't do this first, your select code won't work
password.setSelectionRange(0, password.value.length);
alert('Senha Incorreta ! tente novamente...');
}
}
input.addEventListener("keydown", function(event){
if (event.keyCode === 13){
// No reason to simulate a button click. Just call the code that needs to be run.
validate();
}
});