简体   繁体   English

IE11中未定义Javascript函数

[英]Javascript function is undefined in IE11

I wrote a sample html page to show a popup div, it's working in firefox, but not in IE. 我写了一个示例html页面来显示弹出div,它在Firefox中有效,但在IE中不起作用。 it said the function is undefined. 它表示该函数未定义。

Here is my page: 这是我的页面:
and the error message is "'show_popup_div' is undefined" 并且错误消息是“'show_popup_div'未定义”

<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=unicode" />

    <script type="text/javascript">

        function show_popup_div() {
            var imageDiv=document.getElementById("image_div");
            var switchA=document.getElementById("switch_a");
            imageDiv.style.display='block';
        }

        async function hide_popup_div() {
            var imageDiv=document.getElementById("image_div");
            await sleep(5000);
            imageDiv.style.display='none';
        }          

        function sleep(ms) {
            return new Promise(resolve => setTimeout(resolve, ms));
        }

    </script>
</head>
<body>

    <a id="switch_a" onmousemove="show_popup_div()" onmouseout="hide_popup_div()">click me to open a image</a>
    <div id="image_div">
        <img id="image" src="http://www.rd.com/wp-content/uploads/sites/2/2016/02/06-train-cat-shake-hands.jpg" usemap="#map1"/>

    </div>

</body>

How can i fix this? 我怎样才能解决这个问题? Thank you. 谢谢。

我相信,如果没有Jaromanda X提到的Javascript库,Promise函数将与IE不兼容。https ://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise

You don't need JavaScript for this effect, you can use pure CSS using the :hover pseudo-class and the + adjacent-element selector: 您不需要JavaScript即可达到这种效果,您可以使用纯CSS,即:hover伪类和+相邻元素选择器:

#image_div {
    display: none;
}

#switch_a:hover + #image_div {
    display: block;
}

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

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