doushan7997 2013-03-14 22:10
浏览 27
已采纳

jquery切换问题

I am using jquery toggle to show a div with content. Not sure how to explain the issue I am having, but if you go to my test page and click on the first link for Similar Movies (it coincides with the movie 500 Days of Summer) you'll see a panel open with the similar movies. If you go to the next Similar Movies link (coinciding with 10 Things I Hate About You) you'll see that it still controls the first set of movies, meaning it toggles the panel up and down. In fact, all of the Similar Movies links control the first panel. Not sure how to fix this. *REMOVED LINK- NO LONGER NECESSARY- THANKS!

<script type="text/javascript"> 
$(document).ready(function(){
$(".flip").click(function(){
    $("#panel").slideToggle("slow");
  });
});
</script> 

<div class="flip">Similar Movies
</div><!-- end of flip-->

    <div id="panel">
similar movies are echoed here from a database using php...
</div>
  • 写回答

4条回答 默认 最新

  • doufang2228 2013-03-14 22:13
    关注

    Instead of using an ID for your panels, use a class, like this:

    <div class="panel">
      similar movies are echoed here from a database using php...
    </div>
    

    Then in your jQuery:

    $(document).ready(function() {
      $(".flip").click(function() {
        $(this).siblings(".panel").slideToggle("slow");
      });
    });
    

    Using the same ID on more than one element is not recommended, and will especially present problems when using jQuery.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度