php月历类
程序员文章站
2024-01-30 19:52:40
...
1. [文件] php月历类
<meta charset="utf-8"> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript"> <!-- $(function (){ $(".subMenu").hide() $(".menu>td>a").mouseover(function () { $(".subMenu").stop(true,true).hide(0); $(this).parent().find("div.subMenu").slideDown("slow"); $(this).parent().addClass("mainHover") }) $(".menu>td").hover(function () {},function () {$(this).find("div.subMenu").hide(); $(this).removeClass("mainHover") } ) }) --> </script> <style type="text/css"> <!-- #Layer1 { position:absolute; z-index:1; display:none; width:100px; height:100px; background: #ccc; border:1px solid #ccc; padding: 10px; font-size: 14px; color: red; font-weight: bold; } a{ display: block; width: 50px; height: 100%; text-decoration: none; } a:hover{ text-decoration:underline; } --> </style> <?php class calendar{ private $_BiaoJi=1; private $_CurrMon;//当前月 private $_MonNum;//每月天数 private $_WeekNum;//星期 private $_url;//连接; private $_FirstDay;//每月的第一天 private $_LastDay;//每月的最后一天 private $_MonWeekSum;//每月有几个周 //构造方法赋值 function __construct() { $this->_CurrMon= isset($_GET['mon'])?$_GET['mon']: date('n'); $this->_MonNum=array(31,30,31,30,31,30,31,31,30,31,30,31); $this->_WeekNum=array('日','一','二','三','四','五','六'); $this->_url= $this->GetUrl(); $this->_FirstDay= getdate(mktime(0,0,0, $this->_CurrMon,1, date('Y'))); $this->Two(); $this->_LastDay= $this->_MonNum[$this->_CurrMon-1]; $this->_MonWeekSum= $this->MonWeekSum(); } //返回连接 private function GetUrl(){ $_url=$_SERVER['REQUEST_URI']; $_arr= parse_url($_url); parse_str($_arr['query'],$_QueryArr); unset($_QueryArr['mon']); $_str= http_build_query($_QueryArr); return $_arr['path'].'?'.$_str.'&mon='; } //返回二月份天数 private function Two(){ if(date('L')){ return $this->_MonNum[1]=29; }else{ return $this->_MonNum[1]=28; } } //返回每月的星期数 private function MonWeekSum(){ return ceil(($this->_LastDay+$this->_FirstDay['wday'])/7); } //上月 private function PreMon(){ if($this->_CurrMon>1){ return "<a href='".$this->_url.($this->_CurrMon-1)."' style='float:left; margin-left:15%;'><<</a>"; } } private function NextMon(){ if($this->_CurrMon<12){ return "<a href='".$this->_url.($this->_CurrMon+1)."' style='float:right; margin-right:15%;'>>></a>"; } } //月历 private function Mon(){ echo "<table border='1' align='center' width='400'>"; echo "<tr><td colspan='7' align='center'>".$this->PreMon().' '.date("Y").' 年 '.$this->_CurrMon.' 月 月历 '.$this->NextMon()."</td></tr>"; echo "<tr align='center'>"; foreach ($this->_WeekNum as $_arr1){ echo "<td>{$_arr1}</td>"; } echo "</tr>"; for($i=0;$i<$this->_MonWeekSum;$i++){ echo "<tr align='center' class='menu'>"; for($j=0;$j<7;$j++){ if($this->_FirstDay['wday']>0 || $this->_BiaoJi>$this->_LastDay){ echo "<td> </td>"; $this->_FirstDay['wday']--; }else{ if($this->_BiaoJi==date('j')){ echo "<td style='background:red;'><a href='#'>{$this->_BiaoJi}</a><div id='Layer1' class='subMenu'>阳历".$this->_CurrMon."月".$this->_BiaoJi."号"."</div></td>"; }else{ echo "<td><a href='#'>{$this->_BiaoJi}</a><div id='Layer1' class='subMenu'>阳历".$this->_CurrMon."月".$this->_BiaoJi."号"."</div></td>"; } $this->_BiaoJi++; } } echo "</tr>"; } echo "</table>"; } public function show(){ if($this->_CurrMon>0 && $this->_CurrMon<=12){ $this->Mon(); }else{ echo '非法操作'; } } } $_calendar=new calendar(); $_calendar->show(); ?>
2. [文件] php月历类 ~ 70KB