我有这个简单的模板:
<script type="text/template" id="dashboard_tem">
<h2>Dashboard<h2>
</script>
我通过以下方式渲染它:
var tem = $('#dashboard_tem').html();
this.$el.html(_.template(tem, {}));
但是,this.$el
html 变为:
<div>
<h2>Dashboard</h2><h2></h2>
</div>
注意额外的<h2>
在最后。这是为什么?
最佳答案
我认为您希望在将 h2 设置为变量 tem 之前关闭它:
<script type="text/template" id="dashboard_tem">
<h2>Dashboard<h2>
</script>
更改为
<script type="text/template" id="dashboard_tem">
<h2>Dashboard</h2>
</script>
关于javascript - 下划线模板添加额外的 <h2> 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27759137/