dem*_*mhm 7 javascript jquery handlebars.js
我正在使用手柄.他们建议在文档正文中包含模板,如下所示:
<script id="entry-template" type="text/x-handlebars-template">
template content
</script>
Run Code Online (Sandbox Code Playgroud)
我想通过src属性使用模板内容,并将我的模板(质量)存储在单独的文件中.
<script src="/path/to/my.template" id="entry-template" type="text/x-handlebars-template"></script>
Run Code Online (Sandbox Code Playgroud)
问题是如何访问它的co内容?
$('script#entry-template').html() //returns ""
$('script#entry-template').text() //returns ""
Run Code Online (Sandbox Code Playgroud)
您需要获取src属性的值,然后使用XMLHttpRequest请求URI ...此时您最好不要使用a <script type="not-js">.
浏览器不会自动下载未知的脚本类型,也不会使脚本以编程方式访问JS.您可以访问内联脚本,因为它们是DOM的一部分,而外部脚本则不是.