用DIV生成超简单的日历
时间:2008-07-06
来源:互联网
程序中正好要用到日历,自己写了个
网上的那些不要看了,写的太烂了
抛砖引玉,互相指导
网上的那些不要看了,写的太烂了
抛砖引玉,互相指导
复制PHP内容到剪贴板
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
#calendarTitle{
width:210px;
}
#calendarMain{
width:210px;
}
.clear{
clear:both;
}
.titleSpan{
width:30px;
text-align:center;
float:left;
}
.daySpan{
width:30px;
text-align:center;
float:left;
}
-->
</style>
</head>
<body>
<div id="calendarTitle">
<div class="titleSpan">日</div>
<div class="titleSpan">一</div>
<div class="titleSpan">二</div>
<div class="titleSpan">三</div>
<div class="titleSpan">四</div>
<div class="titleSpan">五</div>
<div class="titleSpan">六</div>
<div class="clear"></div>
</div>
<div id="calendarMain">
<?
@date_default_timezone_set('+8');
function week2day($str) {
$days = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
return array_search($str, $days) + 1;
}
$selectTimestamp = time();
$curMonth = date('n', $selectTimestamp);
$curYear = date('Y', $selectTimestamp);
$curDay = week2day(date('D', $selectTimestamp));
$todayNum = date('j', $selectTimestamp);
$curMonthTotal = date('t', $selectTimestamp);
$firstDay = week2day(date('D', mktime(0,0,0,$curMonth,1,$curYear)));
$lastDay = week2day(date('D', mktime(0,0,0,$curMonth,$curMonthTotal,$curYear)));
for($i=0;$i<$firstDay;$i++){
echo('<div class="daySpan"> </div>');
}
for($i=1;$i<=$curMonthTotal;$i++){
if($i == $todayNum){
echo('<div class="daySpan">X</div>');
}else{
echo('<div class="daySpan">'.$i.'</div>');
}
}
?>
</div>
<div class="clear"></div>
</body>
</html>
[ 本帖最后由 idgnarn 于 2008-7-5 23:09 编辑 ] PHP代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
#calendarTitle{
width:210px;
}
#calendarMain{
width:210px;
}
.clear{
clear:both;
}
.titleSpan{
width:30px;
text-align:center;
float:left;
}
.daySpan{
width:30px;
text-align:center;
float:left;
}
-->
</style>
</head>
<body>
<div id="calendarTitle">
<div class="titleSpan">日</div>
<div class="titleSpan">一</div>
<div class="titleSpan">二</div>
<div class="titleSpan">三</div>
<div class="titleSpan">四</div>
<div class="titleSpan">五</div>
<div class="titleSpan">六</div>
<div class="clear"></div>
</div>
<div id="calendarMain">
<?
@date_default_timezone_set('+8');
function week2day($str) {
$days = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
return array_search($str, $days) + 1;
}
$selectTimestamp = time();
$curMonth = date('n', $selectTimestamp);
$curYear = date('Y', $selectTimestamp);
$curDay = week2day(date('D', $selectTimestamp));
$todayNum = date('j', $selectTimestamp);
$curMonthTotal = date('t', $selectTimestamp);
$firstDay = week2day(date('D', mktime(0,0,0,$curMonth,1,$curYear)));
$lastDay = week2day(date('D', mktime(0,0,0,$curMonth,$curMonthTotal,$curYear)));
for($i=0;$i<$firstDay;$i++){
echo('<div class="daySpan"> </div>');
}
for($i=1;$i<=$curMonthTotal;$i++){
if($i == $todayNum){
echo('<div class="daySpan">X</div>');
}else{
echo('<div class="daySpan">'.$i.'</div>');
}
}
?>
</div>
<div class="clear"></div>
</body>
</html>
作者: idgnarn 发布时间: 2008-07-05
有点意思,鼓励。
作者: luzhou 发布时间: 2008-07-06
不错哦
作者: 7717060 发布时间: 2008-07-09

作者: bush 发布时间: 2008-07-09
顶你下
外语人才 翻译人才
外语人才 翻译人才
作者: tuvw242 发布时间: 2008-07-12
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28