简体   繁体   中英

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.

How can this be adapted to allow for more than 1 ID or Class?

// 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 container = $("#optionsModal, #anotherIdElement");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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