简体   繁体   English

有没有办法停止IE9中的这个JavaScript错误

[英]Is there a way to stop this javascript bug in IE9

I have a issue with some javascript code showing overlays in IE9, it works fine in Chrome, Firefox, even IE8. 我在IE9中显示一些JavaScript代码时遇到问题,它在Chrome,Firefox,甚至IE8中都可以正常工作。 However when being run in IE9, several weird things happen. 但是,在IE9中运行时,会发生一些奇怪的事情。 Basically, hovering over the are is meant to make an overlay with some text appear, but in IE9, the first overlay is being cloned or something, so I'm getting a strip with the same styling and position of the first div, but none of the content. 基本上,将鼠标悬停在the上是为了使一些文本出现在叠加层上,但是在IE9中,第一个叠加层已被克隆或其他内容,因此我得到的条形与第一个div的样式和位置相同,但是没有内容。 Here's an example of how the HTML looks: 以下是HTML外观的示例:

<img usemap="#mymap"/>
<map id="mymap">
<area id="first" onmouseover="ShowOverlay(this);" onmouseout="HideOverlays()";>
<area id="second" onmouseover="ShowOverlay(this);" onmouseout="HideOverlays()";>
</map>
<div id="first-Overlay" class="overlay" onmouseover="OverlayOnHover(this);" onmouseout="OverlayMouseOff(this);">
some text here.
</div>
<div id="second-Overlay" class="overlay" onmouseover="OverlayOnHover(this);" onmouseout="OverlayMouseOff(this);">
more text here.
</div>

And the javascript it's attached to is: 附带的javascript是:

<script type="text/javascript">
var PreviousOverlay;
function ShowOverlay(sender) {
    if (PreviousOverlay) {
        PreviousOverlay.style.display = 'none';
    }
    NewOverlay = document.getElementById(sender.id + '-Overlay');
    if (NewOverlay) {
        NewOverlay.style.display = 'inline';
    }
    PreviousOverlay = NewOverlay;

    return false;
}
function HideOverlays() {
    if (PreviousOverlay) {
        PreviousOverlay.style.display = 'none';
    }
    PreviousOverlay = null;
    return false;
}
function OverlayOnHover(Overlay) {
    Overlay.style.display = 'inline';
}
function OverlayMouseOff(Overlay) {
    Overlay.style.display = 'none';
}
</script>

Using the Web Developer tools in IE, I can change the the "first-Overlay" display to inline, and then it will be visible along with the strip that is being returned by getElementById('first-Overlay'). 使用IE中的Web Developer工具,我可以将“ first-Overlay”显示更改为内联,然后它将与getElementById('first-Overlay')返回的条一起显示。 Does anyone know what causes this in IE9? 有人知道IE9中的原因吗? I've really hit a brick wall as far as thinking up workarounds goes. 就考虑解决方法而言,我确实遇到了麻烦。

I tried using jQuery, the bug still happened. 我尝试使用jQuery,但该错误仍然发生。

In the end my workaround was to add a dummy div with absolute positioning, etc in front of the first div. 最后,我的解决方法是在第一个div的前面添加一个具有绝对定位的虚拟div,以此类推。 This div never gets shown, so the bug doesn't have any visible effect. 该div永远不会显示,因此该错误不会产生任何可见效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM