下划线_.template未捕获的语法错误令牌

gh0*_*0st 1 backbone.js underscore.js

我正在研究Addy Osmani的Backbone Fundamentals教程.http://addyosmani.github.io/backbone-fundamentals/#application-view

并在Chrome中获得" 未捕获的SyntaxError:Unexpected token% ".

它指向Underscore.js中的一行以及我的views/app.js中的一行.

在views/app.js中,它指向的行是:

statsTemplate: _.template( $('#stats-template').html() ),
Run Code Online (Sandbox Code Playgroud)

它在错误消息中显示"匿名函数".这是从教程中复制的,所以我不确定它为什么会抛出错误.谢谢

模板标记:

<script type="text/template" id="stats-template">
    <span id="todo-count">
       <strong>
           <%= remaining %>
       </strong>
       <%= remaining === 1 ? 'item':'items'%> left
    </span> 
    <ul id="filters">
        <li> 
            <a class="selected" href="#/">All</a> 
        </li> 
        <li> 
            <a href="#/active">Active</a> 
        </li> 
        <li> 
            <a href="#/completed">Completed</a>
        </li> 
    </ul>
    <% if(completed) {% >
        <button id="clear-completed">Clear completed (<%= completed %>)</button> 
    <% } %> 
</script>
Run Code Online (Sandbox Code Playgroud)

McG*_*gle 5

模板标记具有之间的空间%>,这是造成下划线在所不惜.这个:

<% if(completed) {% >
Run Code Online (Sandbox Code Playgroud)

应该是这样的:

<% if(completed) { %>
Run Code Online (Sandbox Code Playgroud)

小提琴