Html 为客户端模板使用脚本标记,为什么';我不能通过src属性加载吗?

Html 为客户端模板使用脚本标记,为什么';我不能通过src属性加载吗?,html,templates,client-side-templating,Html,Templates,Client Side Templating,这很好(我可以通过id访问dom中的代码段) 我是从文件系统和/或从python-msimplehttpserver运行的。有什么想法吗?这是因为服务器将.html文件作为html文件提供服务。您需要将模板文件设置为不同的文件类型,例如.tpl,并让服务器发送相应的标题。即使您确实通过src引用了模板文件,您将如何访问内容?它不会成为节点的textContent。 <script type="text/x-template" id="todo-item-template"> &l

这很好(我可以通过id访问dom中的代码段)


我是从文件系统和/或从
python-msimplehttpserver
运行的。有什么想法吗?

这是因为服务器将
.html
文件作为html文件提供服务。您需要将模板文件设置为不同的文件类型,例如
.tpl
,并让服务器发送相应的标题。

即使您确实通过
src
引用了模板文件,您将如何访问内容?它不会成为节点的
textContent
<script type="text/x-template" id="todo-item-template">
  <div class="todo-view">
    {blah} {blah}
  </div>
</script>
<script type="text/x-template" id="todo-item-template" src="todo-item-template.html">
Resource interpreted as Script but transferred with MIME type text/html: 
"http://localhost:8000/todo2/todo-stats-template.html".