我尝试了以下脚本无济于事。我在www.1tryten.com上有一系列标签。选项卡会自动旋转并在鼠标悬停时更改。我正在尝试使用它,以便当前活动的选项卡为body标签设置类。本质上,如果tab-1处于活动状态,则主体类将为tab-1等。这是否可行。

$(document).ready(function() {
$("#tabs").tabs({
    event: 'mouseover',
    fx: {
        opacity: 'toggle',
        duration: 'slow',
        show: function(event, ui) { $("body").addClass(ui.tab);}
    }
}).tabs('rotate', 5000, true);
});


这是标签的代码

<div id="tabs" class="tabs-bottom ui-tabs ui-widget ui-widget-content ui-corner-all">
    <div id="tabsone" class="tabsone ui-tabs-panel ui-widget-content ui-corner-bottom" style="">
    <img src="/images/mac-mini-banner.png">
        <h3>Mac Mini Security Mount.  New Mac Mini Mount.</h3>
</div>
<div id="tabstwo" class="tabstwo ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" style="">
    <p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
</div>
<div id="tabsthree" class="tabsthree ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" style="">
    <p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
    <p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
</div>
            <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
                <li id="tabone" class="tabsone ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabsone"><img src="/images/laptop-lock-tab-nav.png"></a></li>
    <li id="tabtwo" class="tabstwo ui-state-default ui-corner-top"><a href="#tabstwo"><img src="/images/computer-lock-tab-nav.png"></a></li>
    <li id="tabthree" class="tabsthree ui-state-default ui-corner-top"><a href="#tabsthree"><img src="/images/locker-tab-nav.png"></a></li>
</ul>
</div>

最佳答案

这是:

$("body").addClass(ui.tab);


试图分配给主体的ui.tab类?因为addClass需要一个字符串作为其参数。您应该做的是:

$("body").attr('class', $(ui.tab).attr('class'));


...假设ui.tab是有效的对象。

关于javascript - jQuery UI选项卡更改主体类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6377884/

10-13 00:46