有人能告诉我为什么会这样吗 console.log()
嵌套在for循环中的语句根本不起作用。事实上,我放在 {
在那之前 %>
似乎根本不会影响代码。
代码如下:
<% for(var i = 0; i < users.length; i++) { %>
<% console.log("hello") %>
<script>checkdate();</script>
<tr id = "data">
<td><%= i + 1 %></td>
<td><%= users[i].name %></td>
<td><%= users[i].email %></td>
<td><%= users[i].material %></td>
<td><%= users[i].frequency %></td>
<!-- <td><%= users[i].date %></td> -->
<td id="date">
<script>
date = "<%= users[i].date %>"
var d_names = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var m_names = new Array("January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December");
var d = new Date(date);
var curr_day = d.getDay();
var curr_date = d.getDate();
var sup = "";
if (curr_date == 1 || curr_date == 21 || curr_date == 31) {
sup = "st";
} else if (curr_date == 2 || curr_date == 22) {
sup = "nd";
} else if (curr_date == 3 || curr_date == 23) {
sup = "rd";
} else {
sup = "th";
}
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
document.write(d_names[curr_day] + " " + curr_date + "<SUP>" + sup + "</SUP> " + m_names[curr_month] + " " +
curr_year);
</script>
</td>
<td>
<a href="/update-user?id=<%= users[i]._id%>" class="btn border-shadow update">
<span class="text-gradient"><i class="fas fa-pencil-alt"></i></span>
</a>
<a class="btn border-shadow delete" data-id=<%= users[i]._id%>>
<span class="text-gradient"><i class="fas fa-times"></i></span>
</a>
</td>
</tr>
<% } %>
更新我更新了代码,使其在for循环中包含if语句,而不是console.log语句,现在ti给出了错误
找不到“<%”的匹配关闭标记。
代码如下:
<% for(var i = 0, todays_date = new Date(), given_date = new Date("<%= users[i].date %>") ; i < users.length; i++) { %>
<% todays_date.setHours(0,0,0,0); given_date.setHours(0,0,0,0); if(todays_date == given_date){ %>
<script>
console.log("cheeky");
</script>
<tr id = "data">
<td><%= i + 1 %></td>
<td><%= users[i].name %></td>
<td><%= users[i].email %></td>
<td><%= users[i].material %></td>
<td><%= users[i].frequency %></td>
<!-- <td><%= users[i].date %></td> -->
<td id="date">
<script>
date = "<%= users[i].date %>"
var d_names = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var m_names = new Array("January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December");
var d = new Date(date);
var curr_day = d.getDay();
var curr_date = d.getDate();
var sup = "";
if (curr_date == 1 || curr_date == 21 || curr_date == 31) {
sup = "st";
} else if (curr_date == 2 || curr_date == 22) {
sup = "nd";
} else if (curr_date == 3 || curr_date == 23) {
sup = "rd";
} else {
sup = "th";
}
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
document.write(d_names[curr_day] + " " + curr_date + "<SUP>" + sup + "</SUP> " + m_names[curr_month] + " " +
curr_year);
</script>
</td>
<td>
<a href="/update-user?id=<%= users[i]._id%>" class="btn border-shadow update">
<span class="text-gradient"><i class="fas fa-pencil-alt"></i></span>
</a>
<a class="btn border-shadow delete" data-id=<%= users[i]._id%>>
<span class="text-gradient"><i class="fas fa-times"></i></span>
</a>
</td>
</tr>
<% } %>
<% } %>
暂无答案!
目前还没有任何答案,快来回答吧!