此代码适用于expamle html但是当我尝试在aspx页面中使用它时不起作用。我也没有很好地完善代码。例如<%= month %>
使用但是第一次在脚本标签中看到html时没有月份,所以我不熟悉编码风格,寻找指导。
<div class="cal2">
<script type="text/template" id="template-calendar">
<div class="clndr-controls">
<div class="clndr-previous-button">‹</div>
<div class="month"><%= month %></div>
<div class="clndr-next-button">›</div>
</div>
<div class="clndr-grid">
<div class="days-of-the-week">
<% _.each(daysOfTheWeek, function(day) { %>
<div class="header-day"><%= day %></div>
<% }); %>
<div class="days">
<% _.each(days, function(day) { %>
<div class="<%= day.classes %>"><%= day.day %></div>
<% }); %>
</div>
</div>
</div>
<div class="clndr-today-button">Today</div>
</script>
</div>
<script src="json2.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script src= "moment-2.8.3.js"></script>
<script src="../src/clndr.js"></script>
答案 0 :(得分:1)
我非常确定问题是因为您使用的是下划线模板:http://underscorejs.org/#template
由于Underscore在模板标记中使用<%= %>
,因此.NET使用相同的分隔符,因此在呈现页面时,.NET错误地认为它可以呈现Underscore模板。
您需要告诉Underscore使用不同的分隔符,请尝试以下操作:
<div class="cal2">
<script type="text/template" id="template-calendar">
<div class="clndr-controls">
<div class="clndr-previous-button">‹</div>
<div class="month">{%= month %}</div>
<div class="clndr-next-button">›</div>
</div>
<div class="clndr-grid">
<div class="days-of-the-week">
{% _.each(daysOfTheWeek, function(day) { %}
<div class="header-day">{%= day %}</div>
{% }); %}
<div class="days">
{% _.each(days, function(day) { %}
<div class="{%= day.classes %}">{%= day.day %}</div>
{% }); %}
</div>
</div>
</div>
<div class="clndr-today-button">Today</div>
</script>
</div>
<script src="json2.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script>
// Tell Underscore to use different template delimiters - {% %}
_.templateSettings = {
interpolate: /\{%=(.+?)%\}/g,
escape: /\{%-(.+?)%\}/g,
evaluate: /\{%(.+?)%\}/g
};
</script>
<script src= "moment-2.8.3.js"></script>
<script src="../src/clndr.js"></script>