我在页面上有几个 div,它们隐藏了我想在单击 div 元素时显示的文本。我如何使用 div 的类来做到这一点?
这是我的 html:
<div id="post-<?php the_ID(); ?>" <?php post_class('team-member'); ?>>
<?php echo get_the_post_thumbnail($page->ID, array(441,293)); ?>
<div class="bio-button">BIO</div>
<h2><?php the_title(); ?></h2>
<h3><?php the_excerpt(); ?></h3>
<div class="team-text">
<p><?php the_content(); ?></p>
</div>
</div>
还有我的jquery:
$('.bio-button').toggle(function () {
$('.team-text',this).show();
}, function () {
$('.team-text',this).hide();
return false;
});
再说一次,我将为 .team-member 设置多个 div,.team-text 是隐藏的,单击 .bio-button 时将显示。
我的 jquery 做错了什么?
最佳答案
.toggle()
已经执行了它自己的显示/隐藏。无需在内部构建函数。
您还可以定位多个类名:$('.bio-button, .team-text')
关于jquery - 切换功能以显示和隐藏与类关联的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15033310/