将其转换为document.write替代解决方案?

问题描述 投票:1回答:1

以下脚本本身可以很好地在页面上运行。但是,在嵌入时,document.write会接管,从而使页面的其余部分被遗忘。我想要通过变量构建所需链接的替代解决方案。对于这些事情,除了document.write以外,我几乎没有经验。任何帮助/指导都将不胜感激。

<script language="javascript" type="text/javascript">
Today = new Date();
TodayDay = Today.getDate();
TodayMon = Today.getMonth();
TodayYear = Today.getYear();
if (TodayYear < 2000) TodayYear += 1900;
escNextYear = TodayYear;
escTwoYears = TodayYear;

if (TodayMon == 0) { TodayMonth = "January"; escNextMonth = "February"; escTwoMonths = "March"; } 
else if (TodayMon == 1) { TodayMonth = "February"; escNextMonth = "March"; escTwoMonths = "April"; }
else if (TodayMon == 2) { TodayMonth = "March"; escNextMonth = "April"; escTwoMonths = "May"; }
else if (TodayMon == 3) { TodayMonth = "April"; escNextMonth = "May"; escTwoMonths = "June"; }
else if (TodayMon == 4) { TodayMonth = "May"; escNextMonth = "June"; escTwoMonths = "July"; }
else if (TodayMon == 5) { TodayMonth = "June"; escNextMonth = "July"; escTwoMonths = "August"; }
else if (TodayMon == 6) { TodayMonth = "July"; escNextMonth = "August"; escTwoMonths = "September"; }
else if (TodayMon == 7) { TodayMonth = "August"; escNextMonth = "September"; escTwoMonths = "October"; }
else if (TodayMon == 8) { TodayMonth = "September"; escNextMonth = "October"; escTwoMonths = "November"; }
else if (TodayMon == 9) { TodayMonth = "October"; escNextMonth = "November"; escTwoMonths = "December"; }
else if (TodayMon == 10) { TodayMonth = "November"; escNextMonth = "December"; escTwoMonths = "January"; }
else if (TodayMon == 11) { TodayMonth = "December"; escNextMonth = "January"; escTwoMonths = "February"; }
else { TodayMonth = TodayMon; }
if (TodayMon == 11) {escTwoYears = TodayYear+1};
if (TodayMon == 11) {escNextYear = TodayYear+1};
if (TodayMon == 10) {escTwoYears = TodayYear+1};
escdate = TodayMon+1 + "/01/" + TodayYear;
escNextMon = TodayMon+2 + "/01/" + TodayYear;  //Vinnie
if (escNextMon > 12) {escNextMon = escNextMon - 12};
escTwoMon = TodayMon+3;
if (escTwoMon > 12) {escTwoMon = escTwoMon - 12};
escdatenext = escNextMon + "/01/" + escNextYear;
escdatetwo = escTwoMon + "/01/" + escTwoYears;

// document.write(escdate);

// document.write(TodayMonth + " " + TodayDay + ", " + TodayYear);
html = '<center>Please click on the month to view<br />the Professional Development Calendar for<br />' +
    '<a href="https://www.escweb.net/ar_esc/catalog/calendar.aspx?monthly&date=' + escdate + '&location=2464" target="_blank"><strong>' + TodayMonth + '</strong></a>, ' +
    '<a href="https://www.escweb.net/ar_esc/catalog/calendar.aspx?monthly&date=' + escNextMon + '&location=2464" target="_blank"><strong>' + escNextMonth + '</strong></a>, and ' +
    '<a href="https://www.escweb.net/ar_esc/catalog/calendar.aspx?monthly&date=' + escdatetwo + '&location=2464" target="_blank"><strong>' + escTwoMonths + '</strong></a>' + 
'<p><div style="border: 3px solid rgb(201, 0, 1); overflow: hidden; margin: 15px auto; max-width: 736px;">' + 
     '<iframe scrolling="yes" src="https://www.escweb.net/ar_esc/catalog/coopcalendar.aspx?location=2464&mode=weekly" style="border: 0px none; height: 600px; width: 100%;"></iframe>'; 

document.write(html);

</script>
javascript document.write
1个回答
1
投票

看来您的页面被“遗忘”的原因是,有些HTML标签没有被关闭。试试这个:

html = '<center>Please click on the month to view<br />the Professional Development Calendar for<br />' +
    '<a href="https://www.escweb.net/ar_esc/catalog/calendar.aspx?monthly&date=' + escdate + '&location=2464" target="_blank"><strong>' + TodayMonth + '</strong></a>, ' +
    '<a href="https://www.escweb.net/ar_esc/catalog/calendar.aspx?monthly&date=' + escNextMon + '&location=2464" target="_blank"><strong>' + escNextMonth + '</strong></a>, and ' +
    '<a href="https://www.escweb.net/ar_esc/catalog/calendar.aspx?monthly&date=' + escdatetwo + '&location=2464" target="_blank"><strong>' + escTwoMonths + '</strong></a>' + 
    '<p><div style="border: 3px solid rgb(201, 0, 1); overflow: hidden; margin: 15px auto; max-width: 736px;">' + 
    '<iframe scrolling="yes" src="https://www.escweb.net/ar_esc/catalog/coopcalendar.aspx?location=2464&mode=weekly" style="border: 0px none; height: 600px; width: 100%;"></iframe>' +
    '</div></p></center>'; 
© www.soinside.com 2019 - 2024. All rights reserved.