运行并考虑这个片段。Mouseenter当移动和移除元素
如果我们将最上面一行(“一”)悬停,它会像预期的那样变成红色。如果我们点击它,它将根据计划被删除。
但是,由于光标现在位于第二行(“2”),因此我期望“mousenter”触发并使该行也变为红色。但是,如果我们保持鼠标仍然在点击鼠标时似乎没有触发。
有没有办法迫使它开火?
function hideMe (elmnt) {
elmnt.remove()
// elmnt.style.display = "none" (is an alternative solution
// that works, but is not what I need)
}
function iveBeenHovered (elmnt) {
\t elmnt.style.backgroundColor = "red"
}
div{
border: 1px solid black;
}
<div onclick="hideMe(this)" onmouseenter="iveBeenHovered(this)">One</div>
<div onclick="hideMe(this)" onmouseenter="iveBeenHovered(this)">Two</div>
<div onclick="hideMe(this)" onmouseenter="iveBeenHovered(this)">Three</div>
在Firefox的Mac第二行立即成为点击第一个,而不是移动 – Johannes
在Chrome浏览器窗口后,红色的正常工作太 – Arkadi
好有趣。我是一个mac/chrome。请注意,只要移动鼠标至少一个像素,mouseenter就会触发。 – swelet