javascript - 为什么我的弹出窗口在 IE 或 Mozilla Firefox 中不起作用?

标签 javascript html css internet-explorer firefox

我尝试制作弹出登录窗口,但它在 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/

相关文章:

javascript - 悬停启动动画并停止悬停将使它倒退

html - 具有自动滚动功能的固定长度的动态列

javascript - js2-mode.el编译错误

javascript - 如何将状态从 child react 到 parent

javascript - 如何在包含日期的字符串中查找最早的日期?

c# - 通过最大化和恢复浏览器窗口调整大小的双滚动条

javascript - 将列表项图像对齐到 html 中心

css - 代码镜像光标位置偏移

javascript - 使用鼠标滚轮放大图像上的特定点

javascript - 如何使用 JavaScript 方法更改字体颜色/取消翻转正文中的文本?