douyuan4357 2018-04-17 09:13
浏览 26
已采纳

你在循环中如何定位一个类?

All the PHP code is in the post loop so when adding a new post it gets also the buttons and when pressing one button it opens all buttons and containers

<div class="col-sm-1 ">
        <span class="btn btn-sm album-song">
            <a class="btn btn-sm show-album-song">&#8897;</a>
            <a class="btn btn-sm hide-album-song">&#8896;</a>
        </span>
    </div>

<div class="container album-songs-show-hide">
    <div class="row">
        <div class="col-sm-4 name"><?php _e('Song Name', 'koband');?></div>
        <div class="col-sm-4"><?php _e('Song Length', 'koband');?></div>
        <div class="col-sm-4"><?php _e('Song Details', 'koband');?></div>
    </div>
    <div class="row" style="background-color: #d6d6d6; border-bottom: 1px solid #000;">         
    <?php foreach ($album_song_details[0] as  $value_song_details) { ?>
        <div class="col-sm-4"><?php echo $value_song_details['name-details']; ?></div>
        <div class="col-sm-4"><?php echo $value_song_details['length']; ?></div>
        <div class="col-sm-4"><?php echo $value_song_details['detail']; ?></div>

        <?php } ?> 
    </div>
</div>

and the jQuery code goes here

$(".album-songs-show-hide").hide();
$(".hide-album-song").hide();
$(".show-album-song").click(function(){
    $(this).find(".album-songs-show-hide").slideDown(1000);// show container elements 
    $(".show-album-song").hide(); // button down hide
    $(".hide-album-song").show(); // button up show

});
  • 写回答

1条回答 默认 最新

  • dongtiran7769 2018-04-17 11:03
    关注

    Thanks to all for commenting solutions but for me this was the working solution for you

    $(".album-songs-show-hide").hide();
    $(".hide-album-song").hide();
    $(".show-album-song").click(function(){
        $(this).closest("div.container").find(".album-songs-show-hide").slideDown(1000);// hide container elemnts 
        $(".show-album-song").hide(); // button down hide
        $(".hide-album-song").show(); // button up show
    
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号