简体   繁体   English

如何适应JavaScript容器以允许多个可能的选择器?

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

The following JavaScript checks to see if the Dialog popup container is the Element clicked and only closes the dialog if an element outside of the container is clicked. 下面的JavaScript检查对话框弹出容器是否被单击元素,并且仅在容器外部的元素被单击时才关闭对话框。

How can this be adapted to allow for more than 1 ID or Class? 如何进行调整以允许超过1个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();
    }
});

Could var container be an array of id/class names instead? var容器可以改为ID /类名的数组吗?

附加到您的选择器...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM