javascript - DIV 获取不到鼠标事件

标签 javascript css html mouseevent

我在 z-index 顶部有一个不可见的 div,我想将其用作点击标签按钮。但它没有得到任何我试图与之关联的鼠标事件。它也不显示用 css 指定的指针。

这是示例:http://www.miguelrivero.net/test/MS-20_mini/index.html

如您所见,我正在使用这个简单的代码(只关注 console.log):

function bgExitHandler(e) {
    Enabler.exit("Background Exit");
    console.log("click");
}

function onMouseHandler(e) {
    console.log("click");
}

document.getElementById("bg-exit").addEventListener("click", bgExitHandler, false);
document.getElementById("bg-exit").addEventListener("onmouseover", onMouseHandler, false);

这是CSS:

#bg-exit {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0px;
    left: 0px;
    cursor: pointer;
    opacity: 0;
}

请问有什么问题吗?

谢谢!

最佳答案

如果您正在使用 addEventListener,事件的名称只是 mouseover,而不是 onmouseover:

document.getElementById("bg-exit").addEventListener("mouseover", onMouseHandler, false);

关于javascript - DIV 获取不到鼠标事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15702100/

相关文章:

javascript - 为什么 jQuery 验证插件规则内的函数不返回 false?

javascript - jquery改变下一页的CSS

javascript - 元素需要点击两次才能运行函数

javascript - 如何在 iOS 中获取 js 文件路径?

javascript - 设计师使用 JavaScript 框架的工作流程

html - 如何让我的链接在我的表中保持在 1 行?

javascript - 获取我的设备的宽度和高度并将它们注入(inject)我的 css 样式

javascript - 否则永远不会执行

javascript - 从客户端在 Telerik RadGrid 中设置 GridCheckBoxColumn

javascript - HTML - 在 Bootstrap 面板上显示/隐藏按钮折叠/展开