0

私はこのコードを持っています:

JS:

    $(document).ready(function(){
       $('nav ul li').click(function () {
          $('aside.' + this.className).toggleClass('opened');
       });
    });

HTML:

<nav>
 <ul>
    <li class="index">Home</li>
    <li class="index2">some text</li>
</ul>
  </nav>

  <aside class="index">
    <div class="picture"></div>
    <h2>Lorem Ipsum</h2>
    <p>Lorem ipsum dolor sit amet</p>
  </aside>

  <aside class="index2">
    <div class="picture"></div>
    <h2>Lorem Ipsum 2</h2>
    <p>Lorem ipsum dolor sit amet 2</p>
  </aside>

One Asideを開いたときに、他のすべてを閉じたいのですが???

4

3 に答える 3

1
$('aside').not('.' + this.className).removeClass('opened');
$('aside.' + this.className).toggleClass('opened');
于 2012-12-13T20:53:50.970 に答える
0
$(document).ready(function(){
   $('nav ul li').click(function () {
      $('aside').removeClass('opened');
      //just do the 1st one at index `0`
      $('aside.' + this.className).eq(0).toggleClass('opened'); 
   });
});
于 2012-12-13T20:47:19.857 に答える
0
$('aside').click(function(){
    $('aside').not(this).removeClass('opened');
});
于 2012-12-13T20:48:12.460 に答える