修改后的php万年历
2017-08-26 14:27
232 查看
<?php
header("content-type:text/html;charset=utf-8");
/**
* Created by PhpStorm.
* User: zk
* Date: 2017/8/25
* Time: 20:34
*/
?>
<?php
//------获取form表单里的年月,并判断是否为空,为空输出当前,不为空表单输出--------
$year = isset($_GET["year"]) && !empty($_GET["year"])?$_GET["year"]:date("Y");
$month = isset($_GET["month"]) && !empty($_GET["month"])?$_GET["month"]:date("m");
//判断form表单的年月,是否为输入正确
if(!is_numeric($year) || !is_numeric($month)){
$year = date("Y");
$month = date("m");
}
$next_month = $month +1;
if($next_month==13){
$next_month = 1;
$next_year = $year + 1;
}else{
$next_month = $next_month;
$next_year = $year;
}
//$last_year = $year - 1;
$last_month = $month -1;
if($last_month== 0){
$last_month=12;
$last_year = $year -1;
}else{
$last_month = $month - 1;
$last_year = $year;
}
//获取当前的年份月份天数
//$year = date("Y");
//$month = date("m");
$days = date("t",mktime(0,0,0,$month,1,$year));//给定月份应有的天数
//获取当前的具体哪一天
$day = date("d");
//获取上个月,和上个月的天数
//$last_month = $month -1;
//获取上个月的时间戳
$temp = mktime(0,0,0,$month-1,1,$year);
$last_days = date("t",$temp);
//获取每月1号对应的星期几
$week = date("N",mktime(0,0,0,$month,1,$year));
//前边的空格数,和前边空格子填得第一个数
$empty_next = $week - 1;
$num_next = $last_days-$empty_next;
//后边的空格数
$num_last = 42 - $days - $empty_next;
?>
<!--css样式添加-->
<style>
tr>th {
background-color: pink;
}
.days {
text-align: center;
background-color: dimgrey;
}
.day_now {
background-color: hotpink;
border:1px solid aquamarine;
color:white;
}
.num_n_l {
text-align: center;
background-color: lightgrey;
}
.a_next {
float: left;
}
.a_last {
float: right;
}
a {
text-decoration: none;
}
#td_form {
width: 500px;
height: 20px;
padding-top: 10px;
background-color: silver;
}
#year,#month {
width: 200px;
height: 30px;
}
</style>
<script src="js/jquery.min.js"></script>
<!--table编写-->
<table border="1" width="500" cellpadding="0" cellspacing="0" align="center">
<caption>万年历<?php echo $year."年".$month."月"?></caption>
<tr>
<td colspan="7" id="td_form">
<!-------------------------form表单-------------------------------->
<form action="" method="get" id="form">
<input type="text" name="year" id="year" placeholder="请输入年份" value="<?php echo $year;?>">
<input type="text" name="month" id="month" placeholder="请输入月份" value="<?php echo $month;?>">
<input type="submit" value="提交">
<a href="wannianli.php">刷新</a>
</form>
</td>
</tr>
<tr>
<th>一</th>
<th>二</th>
<th>三</th>
<th>四</th>
<th>五</th>
<th>六</th>
<th>日</th>
</tr>
<tr>
<?php
//前边的空格子
for($j=0;$j<$empty_next;$j++){
$num_next++;?>
<td class="num_n_l"><?php echo $num_next;?></td>
<?php }
?>
<?php
for($i=1;$i<=$days;$i++){?>
<?php
//判断当前日期
if($i==$day){
$class = "day_now";
}else{
$class = "";
}
?>
<?php if(($i+$empty_next)%7==0){?>
<td class="days <?php echo $class;?>"><?php echo $i;?></td>
</tr>
<tr>
<?php }else{?>
<td class="days <?php echo $class;?>"><?php echo $i;?></td>
<?php }
}
?>
<?php
//后边的空格子
for($k=1;$k<=$num_last;$k++){?>
<?php
if((14-$num_last+$k)%7==0){?>
<td class="num_n_l"><?php echo $k;?></td>
</tr><tr>
<?php
}else{
?>
<td class="num_n_l"><?php echo $k;?></td>
<?php }
}
?>
</tr>
<tr>
<th colspan="7">
<div class="a_next"><a href="wannianli.php?month=<?php echo $last_month;?>&year=<?php echo $last_year;?>">上一月</a></div>
<div class="a_last"><a href="wannianli.php?month=<?php echo $next_month;?>&year=<?php echo $next_year;?>">下一月</a></div>
</th>
</tr>
</table>
<!----jquery代码--需写在html代码之后,前边代码加载完才能执行------>
<script>
$("td").mouseover(function () {
$("td").css("border","1px solid");
$(this).css("border","1px solid yellow");
})
</script>
header("content-type:text/html;charset=utf-8");
/**
* Created by PhpStorm.
* User: zk
* Date: 2017/8/25
* Time: 20:34
*/
?>
<?php
//------获取form表单里的年月,并判断是否为空,为空输出当前,不为空表单输出--------
$year = isset($_GET["year"]) && !empty($_GET["year"])?$_GET["year"]:date("Y");
$month = isset($_GET["month"]) && !empty($_GET["month"])?$_GET["month"]:date("m");
//判断form表单的年月,是否为输入正确
if(!is_numeric($year) || !is_numeric($month)){
$year = date("Y");
$month = date("m");
}
$next_month = $month +1;
if($next_month==13){
$next_month = 1;
$next_year = $year + 1;
}else{
$next_month = $next_month;
$next_year = $year;
}
//$last_year = $year - 1;
$last_month = $month -1;
if($last_month== 0){
$last_month=12;
$last_year = $year -1;
}else{
$last_month = $month - 1;
$last_year = $year;
}
//获取当前的年份月份天数
//$year = date("Y");
//$month = date("m");
$days = date("t",mktime(0,0,0,$month,1,$year));//给定月份应有的天数
//获取当前的具体哪一天
$day = date("d");
//获取上个月,和上个月的天数
//$last_month = $month -1;
//获取上个月的时间戳
$temp = mktime(0,0,0,$month-1,1,$year);
$last_days = date("t",$temp);
//获取每月1号对应的星期几
$week = date("N",mktime(0,0,0,$month,1,$year));
//前边的空格数,和前边空格子填得第一个数
$empty_next = $week - 1;
$num_next = $last_days-$empty_next;
//后边的空格数
$num_last = 42 - $days - $empty_next;
?>
<!--css样式添加-->
<style>
tr>th {
background-color: pink;
}
.days {
text-align: center;
background-color: dimgrey;
}
.day_now {
background-color: hotpink;
border:1px solid aquamarine;
color:white;
}
.num_n_l {
text-align: center;
background-color: lightgrey;
}
.a_next {
float: left;
}
.a_last {
float: right;
}
a {
text-decoration: none;
}
#td_form {
width: 500px;
height: 20px;
padding-top: 10px;
background-color: silver;
}
#year,#month {
width: 200px;
height: 30px;
}
</style>
<script src="js/jquery.min.js"></script>
<!--table编写-->
<table border="1" width="500" cellpadding="0" cellspacing="0" align="center">
<caption>万年历<?php echo $year."年".$month."月"?></caption>
<tr>
<td colspan="7" id="td_form">
<!-------------------------form表单-------------------------------->
<form action="" method="get" id="form">
<input type="text" name="year" id="year" placeholder="请输入年份" value="<?php echo $year;?>">
<input type="text" name="month" id="month" placeholder="请输入月份" value="<?php echo $month;?>">
<input type="submit" value="提交">
<a href="wannianli.php">刷新</a>
</form>
</td>
</tr>
<tr>
<th>一</th>
<th>二</th>
<th>三</th>
<th>四</th>
<th>五</th>
<th>六</th>
<th>日</th>
</tr>
<tr>
<?php
//前边的空格子
for($j=0;$j<$empty_next;$j++){
$num_next++;?>
<td class="num_n_l"><?php echo $num_next;?></td>
<?php }
?>
<?php
for($i=1;$i<=$days;$i++){?>
<?php
//判断当前日期
if($i==$day){
$class = "day_now";
}else{
$class = "";
}
?>
<?php if(($i+$empty_next)%7==0){?>
<td class="days <?php echo $class;?>"><?php echo $i;?></td>
</tr>
<tr>
<?php }else{?>
<td class="days <?php echo $class;?>"><?php echo $i;?></td>
<?php }
}
?>
<?php
//后边的空格子
for($k=1;$k<=$num_last;$k++){?>
<?php
if((14-$num_last+$k)%7==0){?>
<td class="num_n_l"><?php echo $k;?></td>
</tr><tr>
<?php
}else{
?>
<td class="num_n_l"><?php echo $k;?></td>
<?php }
}
?>
</tr>
<tr>
<th colspan="7">
<div class="a_next"><a href="wannianli.php?month=<?php echo $last_month;?>&year=<?php echo $last_year;?>">上一月</a></div>
<div class="a_last"><a href="wannianli.php?month=<?php echo $next_month;?>&year=<?php echo $next_year;?>">下一月</a></div>
</th>
</tr>
</table>
<!----jquery代码--需写在html代码之后,前边代码加载完才能执行------>
<script>
$("td").mouseover(function () {
$("td").css("border","1px solid");
$(this).css("border","1px solid yellow");
})
</script>
相关文章推荐
- 修改PHP 上传文件大小限制
- PHP验证码类代码( 最新修改,完全定制化! )
- PHP 读取和修改大文件的某行内容的代码
- 网上代码研究后修改的PHP登录程序,关闭浏览器session清空,可以设置cookies时间
- PHP像数组一样存取和修改字符串字符
- Yii引入PHPExcel修改其自动加载方法
- php利用ajax双击table修改内容
- PHP---如何修改域名的指定的根目录
- Php wampserver修改根目录
- 修改 ueditor1_4_3-utf8-php 它的图片上传地址
- 修改PHP的memory_limit限制
- 修改php.ini以达到屏蔽错误信息并记录日志
- wampserver修改mysql端口号并启动PHP
- 【php增删改查实例】第二十一节 - 用户修改功能
- php.ini修改php上传文件大小限制的方法详解
- 修改php.ini不生效的问题
- 另一个日历(根据农历网上的寿星万年历修改)最新修改适应FF
- mb_detect_encoding() 运行sitemap.php 字符编码不能转换修改php.ini
- php ajax 表格排序,调整列宽,修改内容