Javascript 使用jquery,可以使用简单的内联模板
我正在尝试使用Jquery在我的页面中使用Handlebar模板。这是一个带有静态数据的简单页面,脚本标记中的模板。这是我的html,问题是Jquery没有加载包含我的模板的脚本标记 var source=$(“#任务模板”).html() 来源未定义,为什么未定义Javascript 使用jquery,可以使用简单的内联模板,javascript,jquery,handlebars.js,Javascript,Jquery,Handlebars.js,我正在尝试使用Jquery在我的页面中使用Handlebar模板。这是一个带有静态数据的简单页面,脚本标记中的模板。这是我的html,问题是Jquery没有加载包含我的模板的脚本标记 var source=$(“#任务模板”).html() 来源未定义,为什么未定义 {{{#任务} {{name}}{{count} {{/tasks} 函数replaceContent(){ 变量任务=[{ 名称:‘A’, 计数:9 }, { 名称:‘B’, 计数:10 }] console.log(
{{{#任务}
-
{{name}}{{count}
{{/tasks}
函数replaceContent(){
变量任务=[{
名称:‘A’,
计数:9
}, {
名称:‘B’,
计数:10
}]
console.log(任务);
var source=$(“#任务模板”).html();
log(“模板src”+源代码)
var template=handlebar.compile(源代码);
$('#内容占位符').html(模板(任务));
}
替换内容();
一些内容
语法的颜色应该为您提供线索:
脚本
标记需要用
关闭,不能使用
:
...
{{/tasks}
更改:
<script type="text/javascript" src="https://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.rc.1.min.js" />
要(添加结束标记):
<script type="text/javascript" src="https://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.rc.1.min.js" />
<script type="text/javascript" src="https://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.rc.1.min.js"></script>