gpt4 book ai didi

javascript - 将 7 天日历更改为 5 天日历

转载 作者:行者123 更新时间:2023-12-02 17:47:47 24 4
gpt4 key购买 nike

我想将当前的 7 天日历更改为 5 天日历。我的 7 天是从周日到周六,我想将其更改为周一到周五。

根据我的了解,有两种主要方法可以实现此目的:

-Hide both Sunday and Saturday columns using css.
-Rerun script to exclude Sunday and Saturday, calculating the dates again.

我已经研究了这两种方法,但无法理解它是如何工作的,我正在寻求一些帮助。

createCalendar()

calendarString = '';
calendarString += '<table width="100%" height="425" data-role="table" border="1" bordercolor="#c0c0c0" cellpadding="0" cellspacing="0">';
calendarString += '<tr>';
calendarString += '<td bgcolor=\"#DDDDDD\" align=\"center\" valign=\"center\" width=\"40\" height=\"22\">Sun<\/td>';
calendarString += '<td bgcolor=\"#DDDDDD\" align=\"center\" valign=\"center\" width=\"40\" height=\"22\">Mon<\/td>';
calendarString += '<td bgcolor=\"#DDDDDD\" align=\"center\" valign=\"center\" width=\"40\" height=\"22\">Tue<\/td>';
calendarString += '<td bgcolor=\"#DDDDDD\" align=\"center\" valign=\"center\" width=\"40\" height=\"22\">Wed<\/td>';
calendarString += '<td bgcolor=\"#DDDDDD\" align=\"center\" valign=\"center\" width=\"40\" height=\"22\">Thu<\/td>';
calendarString += '<td bgcolor=\"#DDDDDD\" align=\"center\" valign=\"center\" width=\"40\" height=\"22\">Fri<\/td>';
calendarString += '<td bgcolor=\"#DDDDDD\" align=\"center\" valign=\"center\" width=\"40\" height=\"22\">Sat<\/td>';
calendarString += '<\/tr>';
thisDate == 1;

for (var i = 1; i <= 6; i++)
{
calendarString += '<tr>';
for (var x = 1; x <= 7; x++)
{
daycounter = (thisDate - firstDay)+1;
thisDate++;
if ((daycounter > numbDays) || (daycounter < 1))
{
calendarString += '<td align=\"center\" bgcolor=\"#888888\" height=\"30\" width=\"40\">&nbsp;<\/td>';
}
else
{
if (checkevents(daycounter,monthNum,yearNum,i,x) || ((todaysDay == x) && (todaysDate == daycounter) && (todaysMonth == monthNum)))
{
if ((todaysDay == x) && (todaysDate == daycounter) && (todaysMonth == monthNum))
{
tempweek = i;
tempdayofweek = x;
calendarString += '<td style=\"vertical-align: top;\" bgcolor=\"#AAFFAA\" height=\"30\" width=\"40\" onClick=showevents(' + daycounter + ',' + monthNum + ',' + yearNum + ',' + i + ',' + x + ')>' + daycounter + '<\/td>';
}
else
{
calendarString += '<td style=\"vertical-align: top;\" bgcolor=\"#FFFFC8\" height=\"30\" width=\"40\" onClick=showevents(' + daycounter + ',' + monthNum + ',' + yearNum + ',' + i + ',' + x + ')>' + daycounter + '<div id="amountevent" style="padding-left:5px;max-height:8px; height:8px; width:30px; max-width:30px;white-space: nowrap;">' + displayeventnumber(daycounter, monthNum, yearNum) + '</div><\/td>';


}
}
else
{
calendarString += '<td style=\"vertical-align: top;\" bgcolor=\"#f9f9f9\" height=\"30\" width=\"40\">' + daycounter + '<\/td>';
}
}
}
calendarString += '<\/tr>';
}
calendarString += '<\/table>';
var object=document.getElementById('calendar');
object.innerHTML= calendarString;
thisDate = 1;

最佳答案

CSS解决方案比较esier(既针对你乱七八糟的代码,又针对跳2天的问题),但是修改JS应该会更好。

它们是第一个和最后一个元素,所以你可以这样做:

table td:first-child, table td:last-child {
display: none;
}

问题:last-child 不适用于较旧的浏览器 (IE<9)。解决方案:jQuery 可以跨浏览器工作:

$('table td:first-child, table td:last-child').remove() 

注意:您确定您的意思是 thisDate == 1; 吗?还是单个=?

关于javascript - 将 7 天日历更改为 5 天日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21611236/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com