无法让Zurb Foundation手风琴工作

时间:2015-06-08 15:24:55

标签: javascript zurb-foundation accordion

我正在使用Zurb的基金会,试图使用手风琴js建立一个FAQ页面。但它不起作用,我不明白为什么。所有js文件都在js文件夹中。这是我的整个页面:

<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/foundation.css" />
<link rel="stylesheet" href="css/app.css">
<script src="js/vendor/modernizr.js"></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 class="accordion" data-accordion>
        <li class="accordion-navigation">
            <a href="#panel13a">Question</a>
            <div id="panel13a" class="content">
            Answer
            </div>
        </li>
    </ul>
</div>    
<script>
$('#myAccordionGroup').on('toggled', function (event, accordion) {
console.log(accordion);
});
</script>
<script src="js/vendor/jquery.js"></script>
<script src="js/foundation/foundation.js"></script>
<script src="js/foundation/foundation.accordion.js"></script>
</body>
</html>

我是HTML网站的新手,很抱歉,如果它是愚蠢的话。

2 个答案:

答案 0 :(得分:1)

您正在使用HTML中不存在的id定位您的手风琴。

您需要将id添加到HTML中,如下所示:

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

同时更改脚本的顺序,以便自定义手风琴在其他所有内容后加载。

<script src="js/vendor/jquery.js"></script>
<script src="js/foundation/foundation.js"></script>
<script src="js/foundation/foundation.accordion.js"></script>

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

这是一个有效的CodePen:http://codepen.io/anon/pen/jPmRyB

答案 1 :(得分:0)

你忘记了$(文件).foundation();

http://foundation.zurb.com/docs/javascript.html - 初始化基础