如何在 javascript 函数中包含多个 class/sub-class

How to include more than one class/sub-class in a javascript function

我有这个javascript:

$(document).ready(function() {
    $('#holder').toggleClass("visible");

    $('a.link').click(function(event) {
        // Over-rides the link
        event.preventDefault();
        // Sets the new destination to the href of the link
        newLocation = this.href;
        color = $(this).data("color");
        $('body').css('background-color', color );
        $('#holder').css('opacity','0' );
        // Delays action
        window.setTimeout(function() {
            // Redirects to new destination
                window.location = newLocation;
        }, 250);
    });

    $('h1').click(function(event) {
        $('#holder').toggleClass("visible");
    });

});

我想将 class body 的用法更改为 body.subsection.container 之类的用法。我该怎么做呢 ?

我还想包含多个 class,例如 body.subsection.container1body.subsection.container2

非常感谢对此的任何帮助。

干杯,

格雷格

假设您的意思是在 body 元素中某处带有 class 小节的元素中找到带有 class container1 或 container2 的元素,您可以这样做:

$('body .subsection .container1,body .subsection .container2')

body.subsection.container 会找到 本身 有 class 小节和 class 容器的正文标签。