0

私が持っている単純なアコーディオンをslideToggleすると、アコーディオンが開いているか閉じているかに応じて、link要素のクラスと、アコーディオン全体をラップする.revealBox divを変更したいと思います

私のjqueryは

$(document).ready(function() {
    // choose text for the show/hide link - can contain HTML (e.g. an image)
    var showText = 'Hide Information';
    var hideText = 'Show Information';
    var is_visible = false;
    $('.collapseLink').append('<span class="dottedBot">' + showText + '</span>');
    $('.revealBoxContents').show();
    $('a.collapseLink').click(function() {
        // switch visibility
        is_visible = !is_visible;
        // change the link depending on whether the element is shown or hidden
        $(this).html((!is_visible) ? showText : hideText);
        // toggle the display - uncomment the next line for a basic "accordion" style
        //$('.toggle').hide();$('a.toggleLink').html(showText);
        $(this).parent().next('.revealBoxContents').slideToggle('slow');
        // return false so any link destination is not followed
        return false;
    });
    // toggle the bottom link
    $('.collapseLink').click(function() {
        $(this).parents('.revealBoxContents').stop(true, true).slideToggle('slow');
        $(".collapseLink").html((!is_visible) ? showText : hideText);
        $(this).parent('.item').toggleClass('current');

    });
});

私のURLは

http://satbulsara.com/NSJ-local/eqs1.htm

ありがとう、

4

2 に答える 2

3

要素でaddClass()関数を使用したいとします。

http://api.jquery.com/addClass/

jQueryのドキュメントにあるようにtoggleClass()を使用してこれを行うこともできます。

$('div.foo').toggleClass(function() {
      if ($(this).parent().is('.bar')) {
        return 'happy';
      } else {
        return 'sad';
      }
});

http://api.jquery.com/toggleClass/

于 2011-05-24T17:05:46.987 に答える
1

jquery のaddClass()およびremoveClass()を使用して、クラスを追加および削除できます。

于 2011-05-24T17:16:06.530 に答える