Heim  >  Artikel  >  Backend-Entwicklung  >  PHP输出台历 PHP实现日历效果

PHP输出台历 PHP实现日历效果

WBOY
WBOYOriginal
2016-06-13 13:11:52905Durchsuche

PHP输出日历 PHP实现日历效果

<style type="text/css">

#tc_calendar{width:250px;}
#tc_title{height:33px;line-height:33px;text-align:right;overflow:hidden;}
#tc_title strong{font-weight:bold;font-size:14px;}
#tc_calendar{border-collapse:collapse;}
#tc_calendar td{text-align:center;width:35px;height:20px;line-height:20px;background-color:#efefef;border-bottom:1px solid #fff;border-right:1px solid #fff;}
#tc_calendar .even td{background-color:#e6e6e6;}
#tc_calendar td .current{display:block;background-color:#f60;color:#fff;}
#tc_calendar .current{background-color:#f60!important;color:#fff;}
#tc_week td{color:#fff;background-color:#373737;}

</style>

<?php $mdays=date("t");    //当月总天数
$datenow=date("j");  //当日日期
$monthnow=date("n"); //当月月份
$yearnow=date("Y");  //当年年份
//计算当月第一天是星期几
$wk1st=date("w",mktime(0,0,0,$monthnow,1,$yearnow));
$trnum=ceil(($mdays+$wk1st)/7); //计算表格行数
//以下是表格字串
$tabstr="<table id=tc_calendar><tr id="tc_week">
<td>日</td>
<td>一</td>
<td>二</td>
<td>三</td>
<td>四</td>
<td>五</td>
<td>六</td>
</tr>";

for($i=0;$i";
   for($k=0;$k$mdays+$wk1st-1) ? $dayecho="&nbsp" : $dayecho=$tabidx-$wk1st+1;
      //突出标明今日日期
      // $dayecho="<span style='\"background-color:red;color:#fff;\"'>$dayecho</span>";
      if($dayecho==$datenow){$todaybg = " class=current";}
      else{$todaybg = "";}
      $tabstr.="<td>$dayecho</td>";
   }
   $tabstr.="";
}
$tabstr.="";
?>

<div id="tc_calendardiv">
<div id="tc_title">{date("Y")}年<strong> {date("m")}月</strong>
</div>
<?php echo $tabstr;?>
</div>

?

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn