calendar month with 5 rows calendar month with 6 rows
我正在使用HTML和JavaScript创建动态日历;我想根据特定月份需要5行还是6行来显示整个月来调整表格单元格的高度和宽度。
我想使用JavaScript/jQuery选择HTML表中的单元格,这样就可以在条件语句中使用它的单元格文本来调整日历的大小。代码块需要如下所示:
var td = $(td) // selects all <td> elements
var tdCheck6 = $(...) // selects cell text of cell in 1st row and 6th column
var tdCheck7 = $(...) // selects cell text of cell in 1st row and 7th column
/* using Monday as the first day of the week, if (Saturday is the first day
of one particular month AND the month has 31 days) OR (Sunday is the first day
of the month AND the month has more than 29 days: that month will need 6 rows) */
if ((tdCheck6 == "1" && daysInMonth == 31) || (tdCheck7 == "1" && daysInMonth > 29)) {
td.style.cssText = "height: 100px; width: 14.29%;";
}
// use default cell dimensions for 5 rows
else {
td.style.cssText = "height: 120px; width: 14.29%;";
} 通过检查这些条件,日历将根据月份重新调整日历视口以适合5或6行。
发布于 2019-04-21 01:41:45
您可以简单地在Jquery中使用:nth-child() Selector。
示例:$("td:nth-child(1)").text()
有关更多详细信息,请访问https://api.jquery.com/nth-child-selector/
https://stackoverflow.com/questions/55775970
复制相似问题