javascript - 页面上有多个 Accordion ?

标签 javascript jquery css html

我正在使用 Accordion ... https://jsfiddle.net/y7czusd7/1/

    $(".tab_content").hide();
    $(".tab_content:first").show();

  /* if in tab mode */
    $("ul.tabs li").click(function() {

      $(".tab_content").hide();
      var activeTab = $(this).attr("rel"); 
      $("#"+activeTab).fadeIn();        

      $("ul.tabs li").removeClass("active");
      $(this).addClass("active");

      $(".tab_drawer_heading").removeClass("d_active");
      $(".tab_drawer_heading[rel^='"+activeTab+"']").addClass("d_active");

    });
    $(".tab_container").css("min-height", function(){ 
      return $(".tabs").outerHeight() + 50;
    });
    $(".tab_drawer_heading").click(function() {

      $(".tab_content").hide();
      var d_activeTab = $(this).attr("rel"); 
      $("#"+d_activeTab).fadeIn();

      $(".tab_drawer_heading").removeClass("d_active");
      $(this).addClass("d_active");

      $("ul.tabs li").removeClass("active");
      $("ul.tabs li[rel^='"+d_activeTab+"']").addClass("active");
    });

如您所见,我尝试在同一页面上使用 2 个,但只有第一个工作正常,我该如何解决这两个问题?

谢谢!

最佳答案

您需要在同一页面上使用唯一的 DOM id 才能解决它无法正常工作的原因。

关于javascript - 页面上有多个 Accordion ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46969130/

相关文章:

javascript - 如何重新启用 meteor 中的不安全功能

javascript - window.location.replace 不适用于 jquery

javascript - Angular UI Router - 访问 ui View 之外的 $scope

javascript - jQuery i++ 和 i-- 问题

jquery - asp MVC : Is it possible to determine how a controller method was called?

jquery - Highstock 带有日期选择器和非默认日期

javascript - jQuery - ajax 返回未知数字

javascript - 为一个元素设置长度(高度或宽度)减去另一个元素的可变长度,即 calc(x - y),其中 y 未知

html - 如何阻止文本重叠?

javascript - 在 React 应用程序中根据状态更改动画 SVG 行