我试图用简单的英语做到这一点:我从鼠标悬停事件中有一个打开的 div,当我将鼠标从 div 中取出时,它会在鼠标移出时关闭,完美。我需要的是,当我鼠标移出时,如果我将鼠标移到具有 x 类或 y 类的 div 上,openDiv 将不会关闭,除了 x 类或 y 类之外的任何其他 div 上的任何鼠标移出都会导致 openDiv 关闭。
这是我到目前为止所拥有的,但它不起作用:
$("#openDiv").mouseout(function () {
var $c = $(e.target); //div where mouse is
if ($c.is('div.x') || ('div.y')) //if div where mouse is has class x or y
{
$("#openDiv").show(); //show or keep open from the mouseover event
} else {
$("#openDiv").hide(); //hide openDiv if mouse is anywhere outside openDiv or div with class x or y
}
});
更新: 我需要更多帮助来选择有效的答案!jsfiddle.net/bUzPG/8 悬停在类 x、y 或 z 上使其保持打开状态,悬停在 x 或 z 上会使 openDiv 变为粉红色,但悬停在 openDiv 之外也会将其变为粉红色,此时它应该变为灰色并隐藏它。知道如何使它变灰并隐藏吗?