这工作正常(我能够通过 id 访问 dom 中的代码段)
<script type="text/x-template" id="todo-item-template">
<div class="todo-view">
{blah} {blah}
</div>
</script>
但是如果我把模板放在外部资源中,我在dom中找不到它:
<script type="text/x-template" id="todo-item-template" src="todo-item-template.html">
chrome 给我一个我认为无关紧要的警告:
Resource interpreted as Script but transferred with MIME type text/html:
"http://localhost:8000/todo2/todo-stats-template.html".
我正在从文件系统和/或 python -m SimpleHTTPServer
运行。有什么想法吗?
最佳答案
这是因为服务器将 .html
文件作为 HTML 文件提供。您将希望模板文件是不同的文件类型,例如 .tpl
并让服务器发送适当的 header 。
关于html - 为客户端模板使用脚本标签,为什么我不能通过 src 属性加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13939084/