我有一个 javascript 函数来打开和关闭一个模态,它检查模态是否打开和关闭,但第一次需要单击 2 次才能触发,直到您刷新页面然后您必须再次单击 2 次。
Javascript:
function ToggleModal(Box) {
var Modal = document.getElementById(Box);
var Display = Modal.style.display;
if(Display == 'none')
{
Modal.style.display = 'block';
document.getElementById('Wrapper').style.overflow = 'hidden';
}
else
{
Modal.style.display = 'none';
}
}
CSS:
.Modal {
display: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url("../IMG/Modal.png");
background-repeat: repeat;
z-index: 2000;
}
我的分区:
<div id="Login" class="Modal">
<div id="LoginForm" class="Form">
<div class="ModalTitle">Sign In <a href="#" class="Toggle" onclick="ToggleModal('Login');"></a></div>
<div class="ModalBody">
<form id="LForm" action="/Assets/PHP/Login/Login.php" method="POST">
<label for="User">Username:</label>
<input id="User" type="text" name="User" class="Input" placeholder="Username" />
<label for="Pass">Password:</label>
<input id="Pass" type="password" name="Pass" class="Input" placeholder="Password" />
</form>
<div class="Clear"></div>
</div>
</div>
</div>
Logo div id 没有样式。