jquery - 切换功能以显示和隐藏与类关联的元素

标签 jquery html css wordpress

我在页面上有几个 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/

相关文章:

jquery - 如何动态调整DIV高度?

java - 使用 JavaFx 创建 PDF 设计

javascript - PHP 动态 CSS ... 在 Javascript 中?

javascript - 隐藏模式弹出窗口后显示边框的 Bootstrap 导航栏

CSS 不透明度 + 调整大小导致图像在 firefox 37 上重复

javascript - 如何在 Bootstrap 中创建切换按钮

php - 当数据以 JSON 格式发送时,使用 php 返回的数据

jquery - jQuery 对话框上的动态按钮名称

javascript - 单击时背景颜色消失

python - 使用Python网络抓取公交车时刻表