2

トグルが開いたら「表示」リンクを非表示にし、トグルを閉じることができるようにするために「blablabla」の最後に「閉じる」リンクを追加するには、以下のjqueryに何を追加する必要がありますか)(保持遅い効果)

jQuery:

var $j = jQuery.noConflict();
$j(function(){
    $j('#containertoggle').on('click', 'a.opener', function(){
        $j(this).next().toggle('slow')
    });
});

HTML :

<ul id="containertoggle">
    <li>
        <a class="opener">show</a>
        <div style="display: none;">
            <p>blablablabla</p>
        </div>
    </li>
    <li>
        <a class="opener">show</a>
        <div style="display: none;">
            <p>blablablabla</p>
        </div>
    </li>
</ul>
4

2 に答える 2

1

このアプローチを試すことができます。

また、 にスタイルを追加しないようにすることをお勧めしますstyle attribute。代わりにクラスを使用してください。

var $j = jQuery.noConflict();
$j(function () {
    $j('#containertoggle').on('click', 'a.opener', function () {    
        var $this = $j(this);
        $this.next('div').show('slow');
        $this.nextAll('a.closer').first().removeClass('hide');
        $this.addClass('hide');
    });

    $j('#containertoggle').on('click', 'a.closer', function () {       
        var $this = $j(this);
        $this.prev('div').hide('slow');
        $this.prevAll('a.opener').first().removeClass('hide');
        $this.addClass('hide');
    });
});

フィドルをチェック

于 2013-06-20T18:31:49.297 に答える