此代码在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>
这是插件主页http://kylestetz.github.io/CLNDR/
最佳答案
我很确定问题会出在,因为您使用的是下划线模板: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>
关于javascript - 日历插件示例在.net上不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29256642/