所以我正在完成一项任务,我现在只有几步才能完成任务,直至完成。这是我到目前为止的代码,我需要做的是先关闭" var week"在一个新的线路和香港专业教育学院尝试过很多方式/ n但是从来没有时间它打破脚本或什么都不做。另外我需要做的另一件事就是创建一个循环,显示每月的每一天(例如,Mon 1,Tue 2,Wed 3等,直到4月的所有日子都显示出来),对于我的生活,我可以不知道如何做到这一点,所以任何人都可以帮我提一下如何将它们放在一起吗?是的,我已经搜索了一段时间如何创建一个空间,结果没有任何帮助。
编辑:我已经更新了代码,我终于想出了如何显示日子,但我不知道如何显示它们之后的数字,我也想出了如何进行换行,对不起大量的文本。
<script>
var monthArray=["January","February","March","April","May","June","July","August","September","October","November","December"];
var weekDaysArray=["Sun","Mon","Tues","Wed","Thurs","Fri","Sat"];
//The comments below are for the current date but I was not sure if we were supposed to show that
//var todaysDate=new Date();
//document.write(todaysDate);
var currMon=monthArray[3];
document.write(currMon);
document.write("\n");
var d = new Date();
var currYr = d.getFullYear();
document.write(currYr +"<br>");
var week="Week 1 of April.";
document.write(week +"<br>");
for (var i=0;i<weekDaysArray.length;i++)
{
document.write(weekDaysArray[i] + "<br>");
}
</script>
答案 0 :(得分:1)
在HTML中,空白被压缩。如果您在源代码中写了换行符,则不会在HTML中显示换行符(除非您使用CSS或<pre>
)。这同样适用于JavaScript生成的换行符。
尝试document.write("<br>");