$("#editBox").append("<input type='button' value='取消' onclick='closeEditBox()'>");
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>日程表</title>
<style type="text/css">
/* 页面基本样式 */
body, td, input {
font-family:Arial;
font-size:12px;
}
/* 日程表格样式 */
#calTable {
border-collapse:collapse;
border:5px solid #C3D9FF;
}
/* 每日单元格样式 */
td.calBox {
border:1px solid #CCDDEE;
width:100px;
height:80px;
vertical-align:top;
}
/* 每日单元格内日期样式 */
td.calBox div.date {
background:#E8EEF7;
font-size:11px;
padding:2px;
cursor:pointer;
}
/* 每日单元格内周六周日样式 */
td.sat div.date, td.sun div.date{
color:red;
}
/* 今日样式 */
td.calBox div.today {
background:#BBCCDD;
}
/* 周标识样式 */
td.day {
text-align:center;
background:#C3D9FF;
border:1px solid #CCDDEE;
color:#112ABB;
}
/* 当前显示的年月样式 */
#dateInfo {
font-weight:bold;
margin:3px;
}
/* 添加任务div样式 */
#addBox {
display:none;
position:absolute;
width:300px;
border:1px solid #000;
height:100px;
background:#FFFF99;
padding:10px;
}
/* 添加任务内日期样式 */
#taskDate {
height:30px;
font-weight:bold;
padding:3px;
}
/* 按钮样式 */
.taskBtn {
margin:10px;
}
/* 编辑任务div样式 */
#editBox {
display:none;
position:absolute;
width:300px;
border:1px solid #000;
height:60px;
background:#99FF99;
padding:10px;
}
/* 任务样式 */
div.task {
width:98px;
overflow:hidden;
white-space:nowrap;
background:#668CB3;
border:1px solid #FFF;
color:#FFF;
padding:1 2 1 3;
cursor:pointer;
}
</style>
<script type="text/javascript" src="calendar_jquery.js"></script>
<script type="text/javascript">
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); //每月天数
var today = new Today(); //今日对象
var year = today.year; //当前显示的年份
var month = today.month; //当前显示的月份
//页面加载完毕后执行fillBox函数
$(function() {
fillBox();
});
//今日对象
function Today() {
this.now = new Date();
this.year = this.now.getFullYear();
this.month = this.now.getMonth();
this.day = this.now.getDate();
}
//根据当前年月填充每日单元格
function fillBox() {
updateDateInfo(); //更新年月提示
$("td.calBox").empty(); //清空每日单元格
var dayCounter = 1; //设置天数计数器并初始化为1
var cal = new Date(year, month, 1); //以当前年月第一天为参数创建日期对象
var startDay = cal.getDay(); //计算填充开始位置
//计算填充结束位置
var endDay = startDay + getDays(cal.getMonth(), cal.getFullYear()) - 1;
//如果显示的是今日所在月份的日程,设置day变量为今日日期
var day = -1;
if (today.year == year && today.month == month) {
day = today.day;
}
//从startDay开始到endDay结束,在每日单元格内填入日期信息
for (var i=startDay; i<=endDay; i++) {
var mo=month+1;
if(mo<10)
mo="0"+mo;
var dayCounter1=dayCounter;
if(dayCounter1<10)
dayCounter1="0"+dayCounter1;
if (dayCounter==day) {
$("#calBox" + i).html("<div class='date today' id='" + year + "-" +mo+ "-" + dayCounter1 + "' onclick='openAddBox(this)'>" + dayCounter + "</div>");
} else {
$("#calBox" + i).html("<div class='date' id='" + year + "-" +mo+ "-" + dayCounter1 + "' onclick='openAddBox(this)'>" + dayCounter + "</div>");
}
dayCounter++;
}
getTasks(); //从服务器获取任务信息
}
//从服务器获取任务信息
function getTasks() {
var mo=month+1;
if(month+1<10)
mo='0'+mo;
alert(year + "-" + mo );
$.getJSON("calendar.jsp", //服务器页面地址
{
action: "getTasks", //action参数
month: year + "-" +mo //年月参数
},
function(json) { //回调函数
//遍历JSON数组,建立任务信息
$(json).each(function(i){
buildTask(json[i].builddate, json[i].id, json[i].task);
});
}
);
}
//根据日期、任务编号、任务内容在页面上创建任务节点
function buildTask(buildDate, taskId, taskInfo) {
$("#" + buildDate).parent().append("<div id='task"+ taskId +"' class='task' onclick='editTask(this)'>" + taskInfo + "</div>");
}
//判断是否闰年返回每月天数
function getDays(month, year) {
if (1 == month) {
if (((0 == year % 4) && (0 != (year % 100))) || (0 == year % 400)) {
return 29;
} else {
return 28;
}
} else {
return daysInMonth[month];
}
}
//显示上月日程
function prevMonth() {
if ((month - 1) < 0) {
month = 11;
year--;
} else {
month--;
}
fillBox(); //填充每日单元格
}
//显示下月日程
function nextMonth() {
if((month + 1) > 11) {
month = 0;
year++;
} else {
month++;
}
fillBox(); //填充每日单元格
}
//显示本月日程
function thisMonth() {
year = today.year;
month = today.month;
fillBox(); //填充每日单元格
}
//更新年月提示
function updateDateInfo() {
$("#dateInfo").html(year + "年" + (month + 1) + "月");
}
//打开新建任务box
function openAddBox(src) {
$("#taskDate").html(src.id); //设置新建日期
$("#taskInfo").val(""); //初始化新建任务内容
var left = getLeft(src) + 15; //设置左边距
var top = getTop(src) + 15; //设置顶边距
$("#addBox").left(left).top(top).slideDown(); //显示新建任务box
}
//向服务器提交新任务信息
function addTask() {
var taskInfo = $("#taskInfo").val(); //获取任务信息
//检查任务信息是否为空
if ($.trim(taskInfo)=="") {
alert("请输入信息");
} else {
var buildDate = $("#taskDate").html(); //获取任务日期
$.post("calendar.jsp", //服务器页面地址
{
action: "addTask", //action参数
taskInfo: taskInfo, //任务信息参数
buildDate: buildDate //任务日期参数
// taskInfo:"dddd",
// buildDate: "2011-6-9"
},
function(taskId) { //回调函数
buildTask(buildDate, taskId, taskInfo); //建立任务节点
closeAddBox(); //关闭新建任务box
}
);
}
}
//关闭新建任务box
function closeAddBox() {
$("#addBox").slideUp();
}
//打开编辑任务box
function editTask(src) {
$("#taskId").val(src.id.substr(4)); //对任务编号隐藏域赋值
$("#editTaskInfo").val(src.innerHTML); //设置编辑内容
var left = getLeft(src) + 15; //设置左边距
var top = getTop(src) + 15; //设置顶边距
$("#editBox").left(left).top(top).slideDown(); //显示编辑任务box
}
//删除任务
function d
评论5
最新资源