我尝试制作弹出登录窗口,但它在 IE 或 Mozilla Firefox 中不起作用。我使用了 JS、html 和 CSS...
<a href="javascript:void(0)" class="hiddenlink" onclick="toggle_visibility('logBox');">Log In</a>
有JS
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
还有CSS
.boxPosition{
position: absolute;
top: 0;
left: 0;
background-color: rgba(0,0,0,0.7);
display: none;
width: 100%;
height: 100%;
}
不知道问题出在哪里...
感谢您的帮助
最佳答案
下面不是错误,而是避免它以防止错误!
function toggle_visibility(id) {
var e = document.getElementById(id);
if (e.style.display == 'block') {//<-------CORRECT THIS {
e.style.display = 'none';
} else { //<-------------------------------CORRECT THIS {}
e.style.display = 'block';
}//<---------------------------------------CORRECT THIS }
}
<小时/>
下面的测试似乎没问题(隐藏“logBox”没问题)!
我使用 Firefox
function toggle_visibility(id) {
var e = document.getElementById(id);
if (e.style.display == 'block') {//<-------CORRECT THIS {
e.style.display = 'none';
} else { //<-------------------------------CORRECT THIS {}
e.style.display = 'block';
}//<---------------------------------------CORRECT THIS }
}
.boxPosition{
position : absolute;
top : 0;
left : 0;
background-color: rgba(0,0,0,0.7);
display : none;
width : 100%;
height : 100%;
}
<a href="javascript:void(0)" class="hiddenlink" onclick="toggle_visibility('logBox');">Log In</a>
<!--
Maybe your issue come from the part below
we haven't
-->
<div id='logBox' style='display : block;'>
I am the LogBox<br>
Name : <input type='text'/><br>
Pass :<input type='password'/><br>
</div>
结论是:
也许问题不是来自您发布的内容,这看起来没问题!
关于javascript - 为什么我的弹出窗口在 IE 或 Mozilla Firefox 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33179733/