-1

誰かがこれで私を助けることができますか? それぞれの「showfaqanswer」をクリックすると「faqanswer」が表示されるようにしたいだけです。PHP と jQuery コードの何が問題なのかわかりません。助けてくれてありがとう!

<?php query_posts("cat=17&posts_per_page=7&offset=7"); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

<p>
<a href="#" id="showfaqanswer"><?php the_title(); ?></a><br />
</p>

<div id="faqanswer"><?php the_content(); ?></div> 

<?php endwhile; ?>

jQuery(document).ready(function() {
$('#showfaqanswer').click(function(){
$('#faqanswer').nextUntil('#showfaqanswer').show();
});
});
4

2 に答える 2

0

セレクターのドキュメントを読んでください: siblingsを取得するため、兄弟がいない場合は何も選択されません。nextUntil

$('#showfaqanswer').click(function(){

    // get the parent of the current #showfaqanswer, select until the the next p-tag
    $(this).parent().nextUntil('p').show();
});
于 2012-09-29T05:50:17.683 に答える
0

クラスを使用する必要があります。IDは一意でなければならないためです。

これを試してください:

<?php query_posts("cat=17&posts_per_page=7&offset=7"); ?>
<?php $i=1; ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

<p>
<a href="#" id="<?php echo $i;?>" class="fanswer"><?php the_title(); ?></a><br />
</p>

<div id="faqanswer<?php echo $i;?>" style="display:none;"><?php the_content(); ?></div> 
<?php $i++; ?>
<?php endwhile; ?>

jQuery(document).ready(function() {
$('.fanswer').click(function(){
var id = $(this).id;
$('#faqanswer'+id).show();
});
});
于 2012-09-29T06:00:48.343 に答える