基础6手风琴不起作用

时间:2016-01-08 09:20:16

标签: accordion zurb-foundation-6

你能不能在下面的Foundation 6 Accordion sameple代码上帮忙,我无法让它工作。我不确定我错过了什么。另外,我保留所有js和css文件都在同一目录中。

<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<script src="jquery.js"></script>
<script src="foundation.js"></script>
<script src="foundation.accordion.js"></script>
<link rel="stylesheet" href="foundation.css" />

<script>
  $(document).foundation();
</script>

<script>
$('#myAccordionGroup').on('toggled', function (event, accordion) {
console.log(accordion);
});
</script>

</head>
<body>

<div class="row row-padding">
   <div class="small-12 columns"> 
    <h1>FAQ:<h1>
    </div>
</div>

<div class="row row-padding small-12">
    <ul id="myAccordionGroup" class="accordion" data-accordion>
    <li class="accordion-navigation">
        <a href="#panel11a">Question 1</a>
        <div id="panel11a" class="content">
        Answer 1
        </div>
    </li>
    <li class="accordion-navigation">
        <a href="#panel12a">Question 2</a>
        <div id="panel12a" class="content">
        Answer 2
        </div>
    </li>
    <li class="accordion-navigation">
        <a href="#panel13a">Question 3</a>
        <div id="panel13a" class="content">
        Answer 3
        </div>
    </li>
    </ul>
</div>

</body>
</html>

感谢有人最早帮助解决这个问题。

1 个答案:

答案 0 :(得分:3)

好的,对我来说它完美无缺,只需检查一下。你有一些缺课,这是你的主要问题。

首先:

  

accordion的容器需要班级.accordion和。{   属性data-accordionrole="tablist"。请注意,在这些   例如,我们使用<ul>,但您可以使用任何您想要的元素。

在您的代码中,ul标记中没有role=tablist

第二件事是你在<a></a><div></div>

中遗漏了很多

您没有例如aria-controlsdata-tab-content aria-labelledby

关于<a></a>

  

标签标题需要role =&#34; tab&#34;,href,唯一ID和   咏叹调-控件。

关于<div></div>

  

内容窗格需要一个与上述href匹配的ID,   role =&#34; tabpanel&#34;,data-tab-content和aria-labelledby。

你的例子:

<div class="row row-padding small-12">
 <ul class="accordion" data-accordion role="tablist">
  <li class="accordion-navigation">
        <a href="#panel11a" role="tab" class="accordion-title" id="panel11a-heading" aria-controls="panel11a">Accordion 1</a>
        <div id="panel11a" class="accordion-content" role="tabpanel" data-tab-content aria-labelledby="panel11a-heading">
        Answer 1
        </div>
    </li>
    <li class="accordion-navigation">
        <a href="#panel12a" role="tab" class="accordion-title" id="panel12a-heading" aria-controls="panel12a">Accordion 2</a>
        <div id="panel12a" class="accordion-content" role="tabpanel" data-tab-content aria-labelledby="panel12a-heading">
        Answer 2
        </div>
    </li>
    <li class="accordion-navigation">
        <a href="#panel13a" role="tab" class="accordion-title" id="panel13a-heading" aria-controls="panel13a">Accordion 3</a>
        <div id="panel13a" class="accordion-content" role="tabpanel" data-tab-content aria-labelledby="panel13a-heading">
        Answer 3
        </div>
    </li>
    </ul>
</div>

如果你需要我的代码,我用它来检查一切是否有效。

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <link href="scripts/foundation.css" rel="stylesheet" />
</head>
<body>

<div class="row row-padding">
   <div class="small-12 columns"> 
    <h1>FAQ:<h1>
    </div>
</div>

<div class="row row-padding small-12">
 <ul class="accordion" data-accordion role="tablist">
  <li class="accordion-navigation">
        <a href="#panel11a" role="tab" class="accordion-title" id="panel11a-heading" aria-controls="panel11a">Accordion 1</a>
        <div id="panel11a" class="accordion-content" role="tabpanel" data-tab-content aria-labelledby="panel11a-heading">
        Answer 1
        </div>
    </li>
    <li class="accordion-navigation">
        <a href="#panel12a" role="tab" class="accordion-title" id="panel12a-heading" aria-controls="panel12a">Accordion 1</a>
        <div id="panel12a" class="accordion-content" role="tabpanel" data-tab-content aria-labelledby="panel12a-heading">
        Answer 2
        </div>
    </li>
    <li class="accordion-navigation">
        <a href="#panel13a" role="tab" class="accordion-title" id="panel13a-heading" aria-controls="panel13a">Accordion 1</a>
        <div id="panel13a" class="accordion-content" role="tabpanel" data-tab-content aria-labelledby="panel13a-heading">
        Answer 3
        </div>
    </li>
    </ul>
</div>

<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/foundation.js"></script>
<script src="https://cdn.jsdelivr.net/foundation/6.1.1/js/foundation.accordion.js"></script>

<script type="text/javascript">
        $(document).ready(function () {
        $(document).foundation();
    });
</script>
</body>
</html>

将来请查看此链接。这应该对你非常有帮助。

zurb-accordion