我编写了一个示例 html 页面来显示弹出 div,它可以在 Firefox 中工作,但不能在 IE 中工作。它说该函数未定义。
这是我的页面:
错误消息是“'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>
我该如何解决这个问题?谢谢。
最佳答案
我相信如果没有 Jaromanda X 提到的 Javascript 库,Promise 函数根本不兼容 IE。 https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise
关于Javascript 函数在 IE11 中未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45538192/