JavaScript Micro-Templating。如何加载文件模板?

时间:2015-11-28 04:18:32

标签: javascript template-engine

John Resig http://ejohn.org/blog/javascript-micro-templating/

的良好JavaScript微模板

我想动态加载模板

function loader(file) {
    $.ajax({
        method: "get",
        url: file
    })
    .done(function( msg ) {
        console.log(msg);
        tmpl("item_tmpl", dataObject);
    });
loader('temp.html');

temp.html

<script type="text/html" id="item_tmpl">
    <%=text%>
    <%=prof%>"/>    
</script>

但我有错误 未捕获的TypeError:无法读取null

的属性'innerHTML'

更新:

正确的示例http://jsfiddle.net/tomo_thumb/27xEf/3/light/

我只需要将模板传输到外部文件并加载它们......

0 个答案:

没有答案
相关问题