如何调整JavaScript容器以允许多个可能的选择器

how to adapt JavaScript container to allow more than one possible selector?

本文关键字:许多个 选择器 何调整 调整 JavaScript      更新时间:2024-02-11

以下JavaScript检查对话框弹出容器是否为单击的元素,并且只有在单击容器外的元素时才会关闭对话框。

如何将其调整为允许多于一个ID或类?

// Used to close Layout Dialog
$(document).mouseup(function (e) {
    var container = $("#optionsModal");
    if (!container.is(e.target) // if the target of the click isn't the container...
        && container.has(e.target).length === 0) // ... nor a descendant of the container
    {
        container.hide();
        $("#page-cover").hide();
    }
});

var容器是否可以是一个id/类名数组?

附加到选择器。。。

var container = $("#optionsModal, #anotherIdElement");