由两个文件组成:

第一个test.php

<style>
table {
border:1px solid #;
} .fontb {
color:white;
background:blue;
} th {
width:30px;
} td,th {
height:30px;
text-align:center; }
form {
margin:0px;
padding:0px;
}
</style>
<?php
include "calendar.class.php"; $calendar=new Calendar; $calendar->out();

第二个日历类:calendar.class.php

<?php
class 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(, , , $this->month, , $this->year));
$this->days=date("t", mktime(, , , $this->month, , $this->year));
} function out(){
echo '<table align="center">';
$this->chageDate("test.php");
$this->weeksList();
$this->daysList();
echo '</table>';
} private function weeksList(){
$week=array('日','一','二','三','四','五','六'); echo '<tr>';
for($i=; $i<count($week); $i++)
echo '<th class="fontb">'.$week[$i].'</th>'; echo '</tr>';
} private function daysList(){
echo '<tr>';
//输出空格(当前一月第一天前面要空出来)
for($j=; $j<$this->start_weekday; $j++)
echo '<td>&nbsp;</td>'; for($k=; $k<=$this->days; $k++){
$j++;
if($k==date('d'))
echo '<td class="fontb">'.$k.'</td>';
else
echo '<td>'.$k.'</td>'; if($j%==)
echo '</tr><tr>'; } //后面几个空格
while($j%!==){
echo '<td>&nbsp;</td>';
$j++;
} echo '</tr>';
} private function prevYear($year, $month){
$year=$year-; if($year < )
$year = ; return "year={$year}&month={$month}";
} private function prevMonth($year, $month){
if($month == ) {
$year = $year -; if($year < )
$year = ; $month=;
}else{
$month--;
} return "year={$year}&month={$month}";
} private function nextYear($year, $month){
$year = $year + ; if($year > )
$year = ; return "year={$year}&month={$month}";
} private function nextMonth($year, $month){
if($month==){
$year++; if($year > )
$year=; $month=;
}else{
$month++;
} return "year={$year}&month={$month}";
} private function chageDate($url=""){
echo '<tr>';
echo '<td><a href="?'.$this->prevYear($this->year, $this->month).'">'.'<<'.'</a></td>';
echo '<td><a href="?'.$this->prevMonth($this->year, $this->month).'">'.'<'.'</a></td>';
echo '<td colspan="3">';
echo '<form>';
echo '<select name="year" onchange="window.location=\''.$url.'?year=\'+this.options[selectedIndex].value+\'&month='.$this->month.'\'">';
for($sy=; $sy <= ; $sy++){
$selected = ($sy==$this->year) ? "selected" : "";
echo '<option '.$selected.' value="'.$sy.'">'.$sy.'</option>';
}
echo '</select>';
echo '<select name="month" onchange="window.location=\''.$url.'?year='.$this->year.'&month=\'+this.options[selectedIndex].value">';
for($sm=; $sm<=; $sm++){
$selected1 = ($sm==$this->month) ? "selected" : "";
echo '<option '.$selected1.' value="'.$sm.'">'.$sm.'</option>';
}
echo '</select>';
echo '</form>';
echo '</td>'; echo '<td><a href="?'.$this->nextYear($this->year, $this->month).'">'.'>>'.'</a></td>';
echo '<td><a href="?'.$this->nextMonth($this->year, $this->month).'">'.'>'.'</a></td>';
echo '</tr>';
} }

效果:

最新文章

  1. 精简的网站reset 和 css通用样式库
  2. 在Eclipse中如何关联spring-framework的文档和源代码
  3. w-WAITING---
  4. B. Fox And Two Dots
  5. Does not contain a valid host:port authority: Master:8031 (configuration property &#39;yarn.resourcemanager.resource-tracker.address&#39;)
  6. mybatis关联查询
  7. mysql 插入语句
  8. 栈应用之中缀表达式计算 MFC实现(计算器核心)
  9. SQL Server 查看对象的权限
  10. Ztree当节点没有下级时不显示下拉图标
  11. 【JavaScript】设计模式-module模式及其改进
  12. ZOJ 2002 Copying Books 二分 贪心
  13. 使用clipboard.js实现复制内容至剪贴板
  14. xampp打开显示缺少运行库的解决方法
  15. c# 根据唯一码,存缓存 实现12小时内 阅读量+1
  16. intelliJ idea如何安装、配置
  17. 改变input的值不会触发change事件的解决思路
  18. (7)Microsoft office Word 2013版本操作入门_常用技巧
  19. docker学习笔记(二)-dockerfile docker仓库
  20. PHP开发——环境安装

热门文章

  1. Nginx Linux yum安装
  2. realproxy
  3. java webservice maven spring Class Not Found Exception解决
  4. 大楼轮廓 &#183; building-outline
  5. oepnni安装
  6. [原创]分享本人自己PY写的BOOST编译程序(源码)
  7. 信息增益(Information Gain)(转)
  8. 访问localhost文件下的testmysql.php文件报Not Found
  9. .net 分布式架构之分布式锁实现(转)
  10. 马婕 2014MBA专硕考试 报刊选读 7 美国的欧洲时刻(转)