日曆頁面展示
1,mktime()函數的使用,取得目前月的天數及當月1號的星期(2018/3/13)
<?php
$day=date("t",mktime(0,0,0,$mon,1,$year));//当前月的天数 31
$w=date("w",mktime(0,0,0,$mon,1,$year));//当月1号的星期几 42,輸出行事曆的頭部資訊
<?php
echo"<div align='center'>";
echo"<table border='0'>";
echo"<h3><div>{$year}年{$mon}月</div></h3>";
echo "<tr>";
echo "<th>日</th>";
echo "<th class='td1'>一</th>";
echo "<th class='td1'>二</th>";
echo "<th class='td1'>三</th>";
echo "<th class='td1'>四</th>";
echo "<th class='td1'>五</th>";
echo "<th>六</th>";
echo "</tr>";3,遍歷輸出行事曆
分析:
由mktime()函數可知當前月總共天數,當月1號是星期幾,只需要在小於當月總天數時每次進行7天的遍歷輸出,
從當月1號對應的星期幾開始每天加1,循環一次7天就是一行資料,這樣日曆就出來了
程式碼:
<?php
$d=1;
while($d<=$day){
echo"<tr onmouseOver='overTr(this)'onmouseOut='outTr(this)'>";
for($i=1;$i<=7;$i++){//循环输出7天信息
if($d<=$day&&($w<$i||$d!=1)){
echo "<th><a href=''>{$d}</a></th>";
$d++;
}else{
echo"<th> </th>";
}
}
}運行結果如下:
##
新建檔案
<?php
echo "日历的基本显示";
預覽
Clear
- 課程推薦
- 課件下載
課件暫不提供下載,工作人員正在整理中,後期請多關注該課程~ 















