> php教程 > PHP源码 > 본문

php月历类

PHP中文网
풀어 주다: 2016-05-25 17:06:47
원래의
1190명이 탐색했습니다.

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[&#39;mon&#39;])?$_GET[&#39;mon&#39;]:  date(&#39;n&#39;);
        $this->_MonNum=array(31,30,31,30,31,30,31,31,30,31,30,31);
        $this->_WeekNum=array(&#39;日&#39;,&#39;一&#39;,&#39;二&#39;,&#39;三&#39;,&#39;四&#39;,&#39;五&#39;,&#39;六&#39;);
        $this->_url=  $this->GetUrl();
        $this->_FirstDay=  getdate(mktime(0,0,0,  $this->_CurrMon,1,  date(&#39;Y&#39;)));
        $this->Two();
        $this->_LastDay=  $this->_MonNum[$this->_CurrMon-1];
        $this->_MonWeekSum=  $this->MonWeekSum();   
    }
    //返回连接
    private function GetUrl(){
        $_url=$_SERVER[&#39;REQUEST_URI&#39;];
        $_arr=  parse_url($_url);
        parse_str($_arr[&#39;query&#39;],$_QueryArr);
        unset($_QueryArr[&#39;mon&#39;]);
        $_str=  http_build_query($_QueryArr);
        return $_arr[&#39;path&#39;].&#39;?&#39;.$_str.&#39;&mon=&#39;;
    }
    //返回二月份天数
    private function Two(){
        if(date(&#39;L&#39;)){
            return $this->_MonNum[1]=29;
        }else{
            return $this->_MonNum[1]=28;
        }
    }
    //返回每月的星期数
    private function MonWeekSum(){
        return ceil(($this->_LastDay+$this->_FirstDay[&#39;wday&#39;])/7);
    }
    //上月
    private function PreMon(){
        if($this->_CurrMon>1){
            return "<a href=&#39;".$this->_url.($this->_CurrMon-1)."&#39; style=&#39;float:left; margin-left:15%;&#39;><<</a>";
        }
    }
    private function NextMon(){
        if($this->_CurrMon<12){
            return "<a href=&#39;".$this->_url.($this->_CurrMon+1)."&#39; style=&#39;float:right; margin-right:15%;&#39;>>></a>";
        }
    }
    //月历
    private function Mon(){
        echo "<table border=&#39;1&#39; align=&#39;center&#39; width=&#39;400&#39;>";
        echo "<tr><td colspan=&#39;7&#39; align=&#39;center&#39;>".$this->PreMon().&#39; &#39;.date("Y").&#39; 年 &#39;.$this->_CurrMon.&#39; 月 月历 &#39;.$this->NextMon()."</td></tr>";
        echo "<tr align=&#39;center&#39;>";
            foreach ($this->_WeekNum as $_arr1){
                echo "<td>{$_arr1}</td>";
            }
        echo "</tr>";
        for($i=0;$i<$this->_MonWeekSum;$i++){
            echo "<tr align=&#39;center&#39; class=&#39;menu&#39;>";
            for($j=0;$j<7;$j++){
                if($this->_FirstDay[&#39;wday&#39;]>0 || $this->_BiaoJi>$this->_LastDay){
                    echo "<td>&nbsp</td>";
                    $this->_FirstDay[&#39;wday&#39;]--;
                }else{
                    if($this->_BiaoJi==date(&#39;j&#39;)){
                      echo "<td style=&#39;background:red;&#39;><a href=&#39;#&#39;>{$this->_BiaoJi}</a><div id=&#39;Layer1&#39; class=&#39;subMenu&#39;>阳历".$this->_CurrMon."月".$this->_BiaoJi."号"."</div></td>";  
                    }else{
                      echo "<td><a href=&#39;#&#39;>{$this->_BiaoJi}</a><div id=&#39;Layer1&#39; class=&#39;subMenu&#39;>阳历".$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 &#39;非法操作&#39;;
        }
    }
}
$_calendar=new calendar();
$_calendar->show();
?>
로그인 후 복사

2. [文件] php月历类 ~ 70KB     

php月历类月历.zip


관련 라벨:
php
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!