我的手风琴似乎不起作用。点击但没有任何反应。它不会通过js

时间:2017-02-23 03:30:23

标签: javascript html accordion

HTML:

<div class="accordion">
  <div class="accordion-section">
      <a class="accordion-section-title" href="#accordion-1">Test</a>
      <div class="accordion-section-content" id="accordion-1"></div>
  </div>
</div>

我的JS(我从http://inspirationalpixels.com/tutorials/creating-an-accordion-with-html-css-jquery获取):

    jQuery(document).ready(function() {
    function close_accordion_section() {
        jQuery('.accordion .accordion-section-title').removeClass('active');
        jQuery('.accordion .accordion-section-content').slideUp(300).removeClass('open');
    }

    jQuery('.accordion-section-title').click(function(e) {
        // Grab current anchor value
        var currentAttrValue = jQuery(this).attr('href');

        if(jQuery(e.target).is('.active')) {
            close_accordion_section();
        }else {
            close_accordion_section();

            jQuery(this).addClass('active');

            jQuery('.accordion ' + currentAttrValue).slideDown(300).addClass('open'); 
        }
        e.preventDefault();
    });
});

1 个答案:

答案 0 :(得分:0)

您发布的代码对我来说很好看。请务必在标记末尾的页面上包含jQuery JS文件。