0
<div class="test">
 <button>Example</button>
 <div class="example" style="display:none;">Blah</div>
</div>

<div class="test">
 <button>Example</button>
 <div class="example" style="display:none;">Another</div>
</div>

がクリックされたらbuttonしたいのです.exampleが、現在の にあるもの.showだけです。.example.test

4

3 に答える 3

3

特定の HTML で機能する別の方法:

$('button').click(function(){
    $(this).next('.example').show();
});
于 2012-04-29T03:23:37.227 に答える
1

これはあなたが言ったことを正確に行います:

$('button').click(function(){
    $(this).closest('.test').find('.example').show();
});

これは投稿したマークアップでも機能しますが、ボタン と.exampleが兄弟でない場合は機能しません。

$('button').click(function(){
    $(this).siblings('.example').show();
});
于 2012-04-29T03:22:28.047 に答える
0

Hiyaここであなたのケースの動作デモ: http://jsfiddle.net/4bLZF/

これはslideToggle http://api.jquery.com/slideToggle/を使用します

コード

  $(document).ready(function () {

    // Watch for clicks on the "slide" link.
    $('button').click(function () {
        $(this).next(".example").slideToggle(400);
        return false;
    });


});​
于 2012-04-29T03:26:57.880 に答える