<scripttype="text/javascript"src="../../03-jQuery/js/jquery-1.10.2/jquery.js"></script>
<?php
header("Content-type:text/html;charset=utf-8");
/**
* Created by PhpStorm.
* User: lanouhn
* Date: 2017/8/24
* Time: 10:10
*/
//獲取當前的年,月
$year=isset($_GET['year'])&& !empty($_GET['year'])?$_GET['year']:date('Y');
$month=isset($_GET['month'])&& !empty($_GET['month'])?$_GET['month']:date('m');
//if (!is_numeric($year) || !is_numeric($month)){
// echo "<script>alert('請輸入數(shù)字')</script>";
// $year = date('Y');
// $month = date('m');
//}
//判斷下一月
if($month==12){
//12
$next_month=1;
$next_year=$year+1;
}else{
//1-11
$next_month=$month+1;
$next_year=$year;
}
//判斷上一月
if($month==1){
//1
$last_month=12;
$last_year=$year-1;
}else{
//2-12
$last_month=$month-1;
$last_year=$year;
}
//獲取當月一共多少天
$days=date('t');
//獲取本月一號對應的是星期幾 ,也就是說前面要有幾個空td
$weeks=date('w',mktime(0,0,0,$month,1,$year));
//獲取當前月份的第幾天
$day1=date('d');
//獲取上個月的總天數(shù)
//$last_month = $month - 1;
$stamp=mktime(0,0,0,$last_month,1,$year);
$last_days=date('t',$stamp);
//判斷空幾格
if($weeks>0){
$l=$weeks-1;
}else{
$l=6;
}
$temp=$l;
?>
<style>
.last_month{
color:#A9A9A9;
}
td{
border:1px solid#646464;
}
td:hover{
border:1px solid#ffd139;
}
#btn,.btn{
border-radius:5px;
background-color:#ffd139;
border-color:#f3e89b;
}
caption a{
text-decoration-line:none;
color:#363636;
font-weight:bold;
}
caption a:hover{
color:#6e6e6e;
}
#year,#month{
border-radius:3px;
background-color:rgba(255,244,164,0.61);
border-color:#f3e89b;
}
</style>
<!--表單-->
<formaction="10-Almanac.php"id="form1">
<inputtype="text"name="year"placeholder="請輸入年"value="<?phpecho$year?>"id="year">
<inputtype="text"name="month"placeholder="請輸入月"value="<?phpecho$month?>"id="month">
<inputtype="button"value="提交"id="btn">
</form>
<tablewidth="500"border="1"cellspacing="0"cellpadding="0"style="text-align:center ">
<captionstyle="text-align:left;"><?phpecho$year;?>年<?phpecho$month;?>月<ahref="10-Almanac.php"style="float:right">刷新</a></caption>
<trbgcolor="#bdb76b">
<th>一</th>
<th>二</th>
<th>三</th>
<th>四</th>
<th>五</th>
<th>六</th>
<th>七</th>
</tr>
<tr>
<!--{里面加空格?>表示1號對應的星期幾 前面要空格-->
<?php
//上個月天數(shù)
for($j=$last_days-$l+1;$j<=$last_days;$j++){ ?>
<tdclass="last_month"><?phpecho$j;?></td>
<?php } ?>
<!--for計算當前月份天數(shù)-->
<?phpfor($i=1;$i<=$days;$i++){
//添加背景顏色
if($i==$day1){
$color="pink";
}else{
$color="#999";
}?>
<!--判斷換行-->
<?php$l++;?>
<?phpif($l%7==0){ ?>
<tdbgcolor="<?phpecho$color?>"><?phpecho$i;?></td>
</tr>
<tr>
<?php }else{ ?>
<tdbgcolor="<?phpecho$color?>"><?phpecho$i;?></td>
<?php } ?>
<?php } ?>
<!--獲取下個月剩余天數(shù)-->
<?php
if($temp+$days<=35){
$total=35;
}else{
$total=42;
}
?>
<?phpfor($z=1;$z<=$total-$l;$z++){
?>
<?phpif($l%7==0){?>
<tdclass="last_month"><?phpecho$z;?></td>
</tr>
<tr>
<?php }else{?>
<tdclass="last_month"><?phpecho$z;?></td>
<?php }}?>
</tr>
<!--上一頁 下一頁-->
<tr>
<tdcolspan="7">
<ahref="10-Almanac.php?month=<?phpecho$last_month?>&year=<?phpecho$last_year?>"><buttonclass="btn">上一月</button></a>
<ahref="10-Almanac.php?month=<?phpecho$next_month?>&year=<?phpecho$next_year?>"><buttonclass="btn">下一月</button></a>
</td>
</tr>
</table>
<script>
$('#btn').click(function(){
$('#form1').submit();
varyear=$('#year').val();
varmonth=$('#month').val();
year=Number(year);
month=Number(month);
if(isNaN(year)||year==0){
alert('請輸入正確年份!');
return false;
}
if(isNaN(month)||month==0){
alert('請輸入正確月份!');
return false;
}
})
</script>
PHP萬年歷
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
相關(guān)閱讀更多精彩內(nèi)容
- 中華萬年歷推薦系統(tǒng)實踐 - 隨身云技術(shù)團隊 http://tech.ssyun.cn/2017/03/03/re...
- 開發(fā)桌面App的歷史應該已經(jīng)很久遠了,從最初的計算機GUI誕生之后,桌面App也就應運而生了。 在以前開發(fā)桌面Ap...