PHP设计年历类一 (38)
程序员文章站
2024-01-13 15:14:16
...
PHP设计日历类一 (38)
由两个文件组成:
第一个test.php
php include "calendar.class.php"; $calendar=new Calendar; $calendar->out();
第二个日历类:calendar.class.php
phpclass Calendar { private $year; //当前的年 private $month; //当前的月 private $start_weekday; //当月的第一天对应的是周几 private $days; //当前月一共多少天 function __construct(){ $this->year=isset($_GET["year"]) ? $_GET["year"] : date("Y"); $this->month=isset($_GET["month"]) ? $_GET["month"] : date("m"); $this->start_weekday=date("w", mktime(0, 0, 0, $this->month, 1, $this->year)); $this->days=date("t", mktime(0, 0, 0, $this->month, 1, $this->year)); } function out(){ echo ''; $this->chageDate("test.php"); $this->weeksList(); $this->daysList(); echo '
'; } private function weeksList(){ $week=array('日','一','二','三','四','五','六'); echo ''; for($i=0; $i '; } private function daysList(){ echo ') echo ' '.$week[$i].' '; echo ''; //输出空格(当前一月第一天前面要空出来) for($j=0; $jthis->start_weekday; $j++) echo ' '; for($k=1; $kthis->days; $k++){ $j++; if($k==date('d')) echo ' '.$k.' '; else echo ''.$k.' '; if($j%7==0) echo ''; } //后面几个空格 while($j%7!==0){ echo ' '; } private function prevYear($year, $month){ $year=$year-1; if($year 1970) $year = 1970; return "year={$year}&month={$month}"; } private function prevMonth($year, $month){ if($month == 1) { $year = $year -1; if($year 1970) $year = 1970; $month=12; }else{ $month--; } return "year={$year}&month={$month}"; } private function nextYear($year, $month){ $year = $year + 1; if($year > 2038) $year = 2038; return "year={$year}&month={$month}"; } private function nextMonth($year, $month){ if($month==12){ $year++; if($year > 2038) $year=2038; $month=1; }else{ $month++; } return "year={$year}&month={$month}"; } private function chageDate($url=""){ echo ''; $j++; } echo ' '; echo ' '; } }'.$this->prevYear($this->year, $this->month).'">'.''.' '; echo ''.$this->prevMonth($this->year, $this->month).'">'.''.' '; echo ''; echo ''; echo '.$url.'?year=\'+this.options[selectedIndex].value+\'&month='.$this->month.'\'">'; for($sy=1970; $sy 2038; $sy++){ $selected = ($sy==$this->year) ? "selected" : ""; echo ''; } echo ''; echo '.$url.'?year='.$this->year.'&month=\'+this.options[selectedIndex].value">'; for($sm=1; $sm12; $sm++){ $selected1 = ($sm==$this->month) ? "selected" : ""; echo ''; } echo ''; echo ''; echo ' '; echo ''.$this->nextYear($this->year, $this->month).'">'.'>>'.' '; echo ''.$this->nextMonth($this->year, $this->month).'">'.'>'.' '; echo '
效果:
相关文章
相关视频
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
- 最新文章
- 热门排行
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论