1

At my website I have clickable hidden meta tags like page views or Google requests under every article.

This is the code I use:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">

$(document).ready(function(){
         $(".slidingDiv").hide();
        $(".show_hide").show();
     $('.show_hide').click(function(){
    $(".slidingDiv").slideToggle();
    });
 });
 </script>

And this code for PHP:

<p class="postmetadata"><a href="javascript:;" class="show_hide">[Show/hide meta data]</a></p>
<div class="slidingDiv">
<p class="postmetadata">Aufrufe: <?php if(function_exists('the_views')) { the_views(); } ?> </p>
<p class="postmetadata"><?php if(function_exists('stt_terms_list')) echo stt_terms_list() ;?></p>
<p class="postmetadata"><?php if (function_exists('backlinks')) backlinks(); ?></p>
<br>
</div>

I use Wordpress. The problem is, if I click on "Show/hide meta data" every article shows the meta data. I only want the meta data of the article I clicked. This is my website.

ドイツ語の [Zeige/Verstecke Meta-Daten] をクリックする必要があります。これは [Show/hide meta data] と同じです。

4

1 に答える 1

0

jQueryメソッド.next()を使用すると、これは今すぐ機能します。

$('.show_hide').click(function(){
    $(this).next().slideToggle();
});

jQueryメソッド.siblings()を使用すると、要素の順序を並べ替えても機能します。

$('.show_hide').click(function(){
    $(this).siblings('.slidingDiv').slideToggle();
});

jQueryメソッド.closest()を使用すると、要素の深さを再配置した場合でも機能します。

$('.show_hide').click(function(){
    $(this).closest('.span-8').find('.slidingDiv').slideToggle();
});

また、jQuery / Prototypeの競合については、次を参照してください:PrototypeとjQueryを一緒に?

最も簡単な解決策は、一時的なコンテキストを作成することです。

(function($){
    $('.show_hide').click(function(){
        $(this).siblings('.slidingDiv').slideToggle();
    });
}(jQuery));
于 2012-07-18T12:46:51.680 に答える