我对JS很新,我认为我理解了页面组件的加载顺序,但这让我很困惑。
我正在使用基础5,我正在使用手风琴组件。在我的js脚本中,我加载数据并将其放入手风琴中,然后成为mainContainer div的内部html。
<link rel="stylesheet" href="css/foundation.complete.css">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" type="text/css" href="css/myCss.css" />
<script src="js/vendor/modernizr.js"></script>
<script src="js/app.js"></script>
<script src="js/vendor/jquery.js"></script>
<body onload="iniciarPg()">
<div id="principal" class="mainContainer">
<dl class="accordion" data-accordion > </dl>
</div>
function iniciarPg()
{
$(document).foundation({
accordion: { toggleable: true }
});
loadData();
}
</script>
<!--SCRIPTS -->
<script src="js/classie.js"></script>
<script src="js/foundation.min.js"/>
<script src="js/foundation/foundation.accordion.js"/>
</body>
我无法理解的部分是虽然mainContainer的所有内部HTML都被替换了,但如果我从我的html中删除<dl class="accordion" data-accordion > </dl>
,那么当JS加载时,页面不会正确显示accordeon,它会单击时不展开。
答案 0 :(得分:0)
您需要reflow
您的基础插件,因为数据稍后会通过ajax。
function iniciarPg()
{
$(document).foundation({
accordion: { toggleable: true }
});
loadData();
//make sure the ajax has been finished and the HTML is properly set, otherwise move following line to you ajax success handler end.
$(document).foundation('reflow');
}
</script>