【发布时间】:2012-11-05 17:40:21
【问题描述】:
可能重复:
How to outsource a template js to a different file when using Handlebars.js
我正在使用手把。他们建议在文档正文中包含这样的模板:
<script id="entry-template" type="text/x-handlebars-template">
template content
</script>
我想通过 src 属性使用模板内容并将我的模板(大量)存储在单独的文件中。
<script src="/path/to/my.template" id="entry-template" type="text/x-handlebars-template"></script>
问题是如何访问co内容呢?
$('script#entry-template').html() //returns ""
$('script#entry-template').text() //returns ""
【问题讨论】:
-
你能做一个 ajax get 来检索文件的内容吗?
-
谢谢。搜索没找到
-
这个想法是使用浏览器标准机制。当它遇到带有 src 属性的脚本标签时,它会加载它。或不?我已经通过 $('head').append('') 对其进行了测试,并看到了 XMLHttpRequest。 jquery 执行了吗?
-
"text/javascript" 以外的任何其他类型都将转义
-
旁注:id不是script标签的常规属性,看到它用在Handlebars中我很惊讶。
标签: javascript jquery handlebars.js