Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery,可以使用简单的内联模板_Javascript_Jquery_Handlebars.js - Fatal编程技术网

Javascript 使用jquery,可以使用简单的内联模板

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(

我正在尝试使用Jquery在我的页面中使用Handlebar模板。这是一个带有静态数据的简单页面,脚本标记中的模板。这是我的html,问题是Jquery没有加载包含我的模板的脚本标记

var source=$(“#任务模板”).html()

来源未定义,为什么未定义


    {{{#任务}
  • {{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>