【发布时间】:2015-05-30 12:16:20
【问题描述】:
在我的应用程序中,我需要动态更改主 div,我的内容所在的位置,但与此同时,页脚和页眉始终相同。 主要 div 是在grunt-handlebars-layouts 的帮助下创建的一系列车把部分。 每个 div,只要点击一个链接就会改变。 到目前为止,我的代码非常简单:
$( document ).ready(function() {
$('section').on('click', '.next', function(){
moveToNextSection(event);
});
});
function moveToNextSection(event){
event.preventDefault();
var currentSection = event.currentTarget;
var nextSectionId = $(currentSection).find('.next').attr('href');
$(currentSection).closest('section').hide();
// var newSection = find section with nextSectionId as id
// $(newSection).show();
}
home.hbs 部分:
<section id="home">
<h2>Welcome Home of {{projectName}}</h2>
<p>I'm the landing and first page </p>
<a href="aborto" class="next"> Click here to go to second step </a>
</section>
aborto.hbs 部分:
<section id="aborto">
<h1>I'm the second page</h1>
<p>
Sei in cinta e devi abortire? Cerca qui le info necessarie!
</p>
</section>
但我只是意识到,通过我的方法,我需要所有已加载到 DOM 中的 div,而我没有。
任何想法如何在单击链接时加载 hbs 部分?
创建预编译的 Handlebars 模板是我唯一的选择吗?
欢迎任何新方法:)
【问题讨论】:
标签: javascript jquery handlebars.js