JS实现日程安排 日程安排插件
代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EmpWeekPlan.aspx.cs" Inherits="Aepri.InfoDev.DPP.Web.PlanManage.EmpWeekPlan" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>员工周计划</title>
<style type="text/css">
body
{
margin: 0;
padding: 0;
font-size: 12px;
color: #555;
background-color: #fff;
} .table-title
{
border-collapse: collapse;
width: 100%;
border: solid 1px #ddd;
font-size: 12px;
font-weight: bold;
color: #555;
} .table-title td
{
text-align: center;
padding: 5px;
height: 25px;
} .table-days
{
border-collapse: collapse;
width: 100%;
} .table-days td
{
border: solid 1px #ddd;
height: 150px;
vertical-align: top;
width: 14px;
} .td-gray
{
color: #ccc;
background-color: #f7f7f7;
} .div-task-item
{
background-color: #bfecff;
margin-top: 2px;
padding: 2px;
height: 14px;
cursor: default;
/* margin-left: 5px;
margin-right: 5px;*/
} .div-task-item:hover
{
background-color: #ff5588 !important;
} .div-no-task-item
{
margin-top: 2px;
padding: 2px;
height: 14px;
} .td-selected
{
background-color: #e0f2f8 !important;
} .div-day-title
{
text-align: right;
padding: 3px;
} .td-today
{
background-color: #fcd7d7;
} .td-today div:first-child
{
border-top: solid 2px #f72f37;
padding-top: 1px;
} .highlight-task
{
background-color: #ff3366 !important;
color: #fff !important;
}
</style>
<script src="<%=ResolveClientUrl("~/js/jquery-1.7.2.min.js") %>" type="text/javascript"></script>
<script type="text/javascript">
var data = {
empCode: '101',
list: [
//说明:id暂时无用
{ id: '01', taskCode: '001', title: '任务一', content: '测试内容', year: 2016, month: 1, day: 3 },
{ id: '02', taskCode: '001', title: '任务一', content: '测试内容', year: 2016, month: 1, day: 4 },
//{ id: '02', taskCode: '001', title: '任务一', content: '测试内容', year: 2016, month: 1, day: 5 },
{ id: '03', taskCode: '002', title: '任务二', content: '测试内容', year: 2016, month: 1, day: 4 },
//{ id: '04', taskCode: '002', title: '任务二', content: '测试内容', year: 2016, month: 1, day: 5 },
{ id: '05', taskCode: '003', title: '任务三', content: '测试内容', year: 2016, month: 1, day: 5 },
{ id: '06', taskCode: '003', title: '任务三', content: '测试内容', year: 2016, month: 1, day: 6 },
{ id: '07', taskCode: '004', title: '任务四', content: '测试内容', year: 2016, month: 1, day: 6 },
{ id: '08', taskCode: '005', title: '任务五', content: '测试内容', year: 2016, month: 1, day: 6 },
{ id: '09', taskCode: '005', title: '任务五', content: '测试内容', year: 2016, month: 1, day: 7 },
{ id: '10', taskCode: '006', title: '任务六', content: '测试内容', year: 2016, month: 1, day: 7 },
//{ id: '11', taskCode: '006', title: '任务六', content: '测试内容', year: 2016, month: 1, day: 8 },
//{ id: '12', taskCode: '006', title: '任务六', content: '测试内容', year: 2016, month: 1, day: 9 },
{ id: '13', taskCode: '007', title: '任务七', content: '测试内容', year: 2016, month: 1, day: 6 },
{ id: '13', taskCode: '007', title: '任务七', content: '测试内容', year: 2016, month: 1, day: 7 },
{ id: '14', taskCode: '007', title: '任务七', content: '测试内容', year: 2016, month: 1, day: 8 },
//{ id: '15', taskCode: '008', title: '任务八', content: '测试内容', year: 2016, month: 1, day: 6 },
//{ id: '15', taskCode: '008', title: '任务八', content: '测试内容', year: 2016, month: 1, day: 7 },
{ id: '15', taskCode: '008', title: '任务八', content: '测试内容', year: 2016, month: 1, day: 8 },
{ id: '15', taskCode: '008', title: '任务八', content: '测试内容', year: 2016, month: 1, day: 9 },
{ id: '15', taskCode: '009', title: '任务九', content: '测试内容', year: 2016, month: 1, day: 4 },
{ id: '15', taskCode: '009', title: '任务九', content: '测试内容', year: 2016, month: 1, day: 5 },
{ id: '15', taskCode: '010', title: '任务十', content: '测试内容', year: 2016, month: 1, day: 10 },
{ id: '15', taskCode: '010', title: '任务十', content: '测试内容', year: 2016, month: 1, day: 9 },
{ id: '15', taskCode: '011', title: '任务十一', content: '测试内容', year: 2015, month: 12, day: 31 },
{ id: '15', taskCode: '011', title: '任务十一', content: '测试内容', year: 2016, month: 1, day: 1 },
{ id: '15', taskCode: '011', title: '任务十一', content: '测试内容', year: 2016, month: 1, day: 2 },
{ id: '15', taskCode: '011', title: '任务十一', content: '测试内容', year: 2016, month: 1, day: 3 }
]
}; var taskCodeList = new Array();
function createTaskCodeList(data, taskCodeList) {
for (var i = 0; i < data.list.length; i++) {
var bl = true;
for (var j = 0; j < taskCodeList.length; j++) {
if (taskCodeList[j] == data.list[i].taskCode) {
bl = false;
}
}
if (bl) {
taskCodeList.push(data.list[i].taskCode);
}
}
}
createTaskCodeList(data, taskCodeList); $(function () {
$(".table-days").parent().height($(window).height() - $(".table-days").parent().position().top - 10); $("#year").change(function () {
var year = $("#year").val();
var month = $("#month").val();
createPlanTable(year, month);
});
$("#month").change(function () {
var year = $("#year").val();
var month = $("#month").val();
createPlanTable(year, month);
});
gotoToday(); //ie6、7
if ($.browser.msie) {
if (parseInt($.browser.version) == 7 || parseInt($.browser.version) == 6) {
$("#table-days").width($("#table-days").width() - 20);
$("#table-days").parent().height($("#table-days").parent().height() - 15);
}
}
}); //end $ //创建计划表格
function createPlanTable(year, month) {
var html = '';
var table = $("#table-days");
var days = getDaysOfMonth(year, month);
var preDays = getDaysOfPreMonth(year, month);
var week = getWeek(year, month, 1);
var day = preDays - week + 1;
var grayDay = 'td-gray'; //置灰
var current = false;
var today = new Date(); for (var i = 0; i < (days + week - 1) / 7 ; i++) {
html += '<tr>';
for (var j = 0; j < 7; j++) {
day++;
if (current == false && day > preDays) {
day = 1;
grayDay = '';
current = true;
}
if (current == true && day > days) {
day = 1;
grayDay = 'td-gray';
current = false;
} var todayClass = '';
if (current && today.getFullYear() == year && today.getMonth() == month - 1 && today.getDate() == day) {
todayClass = 'td-today';
}
html += '<td day="' + day + '" class=" ' + grayDay + ' ' + todayClass + '"><div class="div-day-title">' + day + '</div>'; var virtualTaskCount = 0;
for (var k = 0; k < data.list.length; k++) {
var model = data.list[k];
if (grayDay == '' && year == model.year && month == model.month && day == model.day) {
var taskIndex = getTaskIndex(taskCodeList, model.taskCode);
for (var m = virtualTaskCount; m < taskIndex; m++) {
html += '<div class="div-no-task-item"></div>';
virtualTaskCount++;
}
html += '<div class="div-task-item" taskCode="' + model.taskCode + '" style="background-color:#' + getColor(taskCodeList, model.taskCode) + ';">' + model.title + '</div>';
virtualTaskCount++;
}
} html += '</td>';
}
html += '</tr>';
}
table.html(html); //优化显示
if (true) {
for (var i = 0; i < taskCodeList.length; i++) {
table.find("tr").each(function () {
var tr = $(this); var taskItem = tr.find("div[taskCode='" + taskCodeList[i] + "']");
if (taskItem.length > 0) {
var k = -1;
while (k != -2) {
k++;
var bl = true;
taskItem.each(function () {
var prev = $(this).parent().find("div:eq(" + (k + 1) + ")");
if (!prev || prev.length == 0) k = -2;
if (prev && prev.attr("taskCode") == taskCodeList[i]) k = -2;
if (!$(this).parent().attr("class") || !prev || prev.length == 0 || prev.attr("class").indexOf("div-no-task-item") == -1) {
bl = false;
}
});
if (bl) {
taskItem.each(function () {
var item = $(this);
var prev = item.parent().find("div:eq(" + (k + 1) + ")");
if (prev.length > 0) {
item.after('<div class="div-no-task-item"></div>');
item.wrap("<div></div>");
prev.after(item.parent().html());
prev.remove();
item.parent().remove();
}
});
} }
}
});
} //end for taskCodeList
//去空
table.find("td").each(function () {
var td = $(this);
while (true) {
var div = td.find("div:last");
if (div.attr("class").indexOf("div-no-task-item") != -1) {
div.remove();
}
else {
break;
}
}
});
} //end 优化显示 //日期td单击双击
table.find("td").each(function () {
var td = $(this);
var grayDay = td.attr('class').indexOf('td-gray') == -1;
td.click(function () {
if (grayDay) {
if (td.attr("class").indexOf("td-selected") != -1) {
td.removeClass("td-selected");
} else {
$(".td-selected").removeClass("td-selected");
td.addClass("td-selected");
}
}
});
td.dblclick(function () {
if (grayDay) {
add(td.attr("day"));
}
});
}); //任务单击双击
$(".div-task-item").each(function () {
var taskItemDiv = $(this);
var taskCode = taskItemDiv.attr("taskCode");
taskItemDiv.click(function (evt) {
$(".div-task-item").removeClass("highlight-task");
table.find("div[taskCode='" + taskCode + "']").addClass("highlight-task");
evt.stopPropagation();
});
taskItemDiv.dblclick(function (evt) {
evt.stopPropagation();
});
});
} //创建新计划
function add(day) {
data.list.push({ id: '15', taskCode: '000', title: '测试新增', content: '测试内容', year: 2016, month: 1, day: parseInt(day) });
createTaskCodeList(data, taskCodeList)
var scrollTop = $("#div-days").scrollTop();
$("#month").change();
$("#div-days").scrollTop(scrollTop);
} //今天
function gotoToday() {
var today = new Date();
$("#year").val(today.getFullYear());
$("#month").val(today.getMonth() + 1);
$("#month").change();
var top = $(".td-today").position().top - $(".table-days").position().top;
var div = $("#div-days").scrollTop(top);
var div = $(".td-selected").removeClass("td-selected");
} //上月
function preMonth() {
var year = $("#year").val();
var month = $("#month").val();
if (month == 1) {
$("#year").val(parseInt(year) - 1);
$("#month").val(12);
} else {
$("#month").val(parseInt(month) - 1);
}
$("#month").change();
$("#div-days").scrollTop($(window).height());
} //下月
function nextMonth() {
var year = $("#year").val();
var month = $("#month").val();
if (month == 12) {
$("#year").val(parseInt(year) + 1);
$("#month").val(1);
} else {
$("#month").val(parseInt(month) + 1);
}
$("#month").change();
$("#div-days").scrollTop(0);
} //获取task索引
function getTaskIndex(taskCodeList, taskCode) {
var pos = 0;
for (var i = 0; i < taskCodeList.length; i++) {
if (taskCodeList[i] == taskCode) {
break;
}
pos++;
}
return pos;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="padding: 5px;">
<div style="padding: 10px;">
<input type="button" value="今天" onclick="gotoToday()" />
<input type="button" value="<" onclick="preMonth()" />
<select id="year" name="year">
<option value="2017">2017</option>
<option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
</select>
年
<select id="month" name="month">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
月
<input type="button" value=">" onclick="nextMonth()" />
</div>
<div style="margin-top: 5px;">
<table class="table-title" cellpadding="0" cellspacing="0">
<tr>
<td>星期一</td>
<td>星期二</td>
<td>星期三</td>
<td>星期四</td>
<td>星期五</td>
<td>星期六</td>
<td>星期日</td>
</tr>
</table>
</div>
<div id="div-days" style="height: 350px; overflow: auto; margin-top: -1px; border-bottom: solid 1px #ddd;">
<table id="table-days" class="table-days" cellpadding="0" cellspacing="0">
</table>
</div>
</div>
</form>
<script type="text/javascript">
//获取当月天数
function getDaysOfMonth(year, month) {
var d = new Date(year, month, 0);
return d.getDate();
} //获取前一个月天数
function getDaysOfPreMonth(year, month) {
if (month == 1) {
month = 12;
year = year - 1;
}
else {
month = month - 1;
}
var d = new Date(year, month, 0);
return d.getDate();
} //获取当天星期数(0到6)
function getWeek(year, month, day) {
var d = new Date(year, month - 1, day);
return d.getDay();
} //颜色集合
var myColor = [
'ccddff',
'ccffdd',
'eeccff',
'eeffcc',
'ffccee',
'ffeecc'
]; //获取颜色
function getColor(taskCodeList, taskCode) {
var pos = 0;
for (var i = 0; i < taskCodeList.length; i++) {
if (taskCodeList[i] == taskCode) {
break;
}
pos++;
if (pos > myColor.length - 1) {
pos = 0;
}
}
return myColor[pos];
}
</script>
</body>
</html>
可以运行的html代码(放一个jquery.js在同一目录即可):
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>员工周计划</title>
<style type="text/css">
body
{
margin: 0;
padding: 0;
font-size: 12px;
color: #555;
background-color: #fff;
} .table-title
{
border-collapse: collapse;
width: 100%;
border: solid 1px #ddd;
font-size: 12px;
font-weight: bold;
color: #555;
} .table-title td
{
text-align: center;
padding: 5px;
height: 25px;
} .table-days
{
border-collapse: collapse;
width: 100%;
} .table-days td
{
border: solid 1px #ddd;
height: 150px;
vertical-align: top;
width: 14px;
} .td-gray
{
color: #ccc;
background-color: #f7f7f7;
} .div-task-item
{
background-color: #bfecff;
margin-top: 2px;
padding: 2px;
height: 14px;
cursor: default;
/* margin-left: 5px;
margin-right: 5px;*/
} .div-task-item:hover
{
background-color: #ff5588 !important;
} .div-no-task-item
{
margin-top: 2px;
padding: 2px;
height: 14px;
} .td-selected
{
background-color: #e0f2f8 !important;
} .div-day-title
{
text-align: right;
padding: 3px;
} .td-today
{
background-color: #fcd7d7;
} .td-today div:first-child
{
border-top: solid 2px #f72f37;
padding-top: 1px;
} .highlight-task
{
background-color: #ff3366 !important;
color: #fff !important;
}
</style>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
var data = {
empCode: '101',
list: [
//说明:id暂时无用
{ id: '01', taskCode: '001', title: '任务一', content: '测试内容', year: 2016, month: 1, day: 3 },
{ id: '02', taskCode: '001', title: '任务一', content: '测试内容', year: 2016, month: 1, day: 4 },
//{ id: '02', taskCode: '001', title: '任务一', content: '测试内容', year: 2016, month: 1, day: 5 },
{ id: '03', taskCode: '002', title: '任务二', content: '测试内容', year: 2016, month: 1, day: 4 },
//{ id: '04', taskCode: '002', title: '任务二', content: '测试内容', year: 2016, month: 1, day: 5 },
{ id: '05', taskCode: '003', title: '任务三', content: '测试内容', year: 2016, month: 1, day: 5 },
{ id: '06', taskCode: '003', title: '任务三', content: '测试内容', year: 2016, month: 1, day: 6 },
{ id: '07', taskCode: '004', title: '任务四', content: '测试内容', year: 2016, month: 1, day: 6 },
{ id: '08', taskCode: '005', title: '任务五', content: '测试内容', year: 2016, month: 1, day: 6 },
{ id: '09', taskCode: '005', title: '任务五', content: '测试内容', year: 2016, month: 1, day: 7 },
{ id: '10', taskCode: '006', title: '任务六', content: '测试内容', year: 2016, month: 1, day: 7 },
//{ id: '11', taskCode: '006', title: '任务六', content: '测试内容', year: 2016, month: 1, day: 8 },
//{ id: '12', taskCode: '006', title: '任务六', content: '测试内容', year: 2016, month: 1, day: 9 },
{ id: '13', taskCode: '007', title: '任务七', content: '测试内容', year: 2016, month: 1, day: 6 },
{ id: '13', taskCode: '007', title: '任务七', content: '测试内容', year: 2016, month: 1, day: 7 },
{ id: '14', taskCode: '007', title: '任务七', content: '测试内容', year: 2016, month: 1, day: 8 },
//{ id: '15', taskCode: '008', title: '任务八', content: '测试内容', year: 2016, month: 1, day: 6 },
//{ id: '15', taskCode: '008', title: '任务八', content: '测试内容', year: 2016, month: 1, day: 7 },
{ id: '15', taskCode: '008', title: '任务八', content: '测试内容', year: 2016, month: 1, day: 8 },
{ id: '15', taskCode: '008', title: '任务八', content: '测试内容', year: 2016, month: 1, day: 9 },
{ id: '15', taskCode: '009', title: '任务九', content: '测试内容', year: 2016, month: 1, day: 4 },
{ id: '15', taskCode: '009', title: '任务九', content: '测试内容', year: 2016, month: 1, day: 5 },
{ id: '15', taskCode: '010', title: '任务十', content: '测试内容', year: 2016, month: 1, day: 10 },
{ id: '15', taskCode: '010', title: '任务十', content: '测试内容', year: 2016, month: 1, day: 9 },
{ id: '15', taskCode: '011', title: '任务十一', content: '测试内容', year: 2015, month: 12, day: 31 },
{ id: '15', taskCode: '011', title: '任务十一', content: '测试内容', year: 2016, month: 1, day: 1 },
{ id: '15', taskCode: '011', title: '任务十一', content: '测试内容', year: 2016, month: 1, day: 2 },
{ id: '15', taskCode: '011', title: '任务十一', content: '测试内容', year: 2016, month: 1, day: 3 }
]
}; var taskCodeList = new Array();
function createTaskCodeList(data, taskCodeList) {
for (var i = 0; i < data.list.length; i++) {
var bl = true;
for (var j = 0; j < taskCodeList.length; j++) {
if (taskCodeList[j] == data.list[i].taskCode) {
bl = false;
}
}
if (bl) {
taskCodeList.push(data.list[i].taskCode);
}
}
}
createTaskCodeList(data, taskCodeList); $(function () {
$(".table-days").parent().height($(window).height() - $(".table-days").parent().position().top - 10); $("#year").change(function () {
var year = $("#year").val();
var month = $("#month").val();
createPlanTable(year, month);
});
$("#month").change(function () {
var year = $("#year").val();
var month = $("#month").val();
createPlanTable(year, month);
});
gotoToday(); //ie6、7
if ($.browser.msie) {
if (parseInt($.browser.version) == 7 || parseInt($.browser.version) == 6) {
$("#table-days").width($("#table-days").width() - 20);
$("#table-days").parent().height($("#table-days").parent().height() - 15);
}
}
}); //end $ //创建计划表格
function createPlanTable(year, month) {
var html = '';
var table = $("#table-days");
var days = getDaysOfMonth(year, month);
var preDays = getDaysOfPreMonth(year, month);
var week = getWeek(year, month, 1);
var day = preDays - week + 1;
var grayDay = 'td-gray'; //置灰
var current = false;
var today = new Date(); for (var i = 0; i < (days + week - 1) / 7 ; i++) {
html += '<tr>';
for (var j = 0; j < 7; j++) {
day++;
if (current == false && day > preDays) {
day = 1;
grayDay = '';
current = true;
}
if (current == true && day > days) {
day = 1;
grayDay = 'td-gray';
current = false;
} var todayClass = '';
if (current && today.getFullYear() == year && today.getMonth() == month - 1 && today.getDate() == day) {
todayClass = 'td-today';
}
html += '<td day="' + day + '" class=" ' + grayDay + ' ' + todayClass + '"><div class="div-day-title">' + day + '</div>'; var virtualTaskCount = 0;
for (var k = 0; k < data.list.length; k++) {
var model = data.list[k];
if (grayDay == '' && year == model.year && month == model.month && day == model.day) {
var taskIndex = getTaskIndex(taskCodeList, model.taskCode);
for (var m = virtualTaskCount; m < taskIndex; m++) {
html += '<div class="div-no-task-item"></div>';
virtualTaskCount++;
}
html += '<div class="div-task-item" taskCode="' + model.taskCode + '" style="background-color:#' + getColor(taskCodeList, model.taskCode) + ';">' + model.title + '</div>';
virtualTaskCount++;
}
} html += '</td>';
}
html += '</tr>';
}
table.html(html); //优化显示
if (true) {
for (var i = 0; i < taskCodeList.length; i++) {
table.find("tr").each(function () {
var tr = $(this); var taskItem = tr.find("div[taskCode='" + taskCodeList[i] + "']");
if (taskItem.length > 0) {
var k = -1;
while (k != -2) {
k++;
var bl = true;
taskItem.each(function () {
var prev = $(this).parent().find("div:eq(" + (k + 1) + ")");
if (!prev || prev.length == 0) k = -2;
if (prev && prev.attr("taskCode") == taskCodeList[i]) k = -2;
if (!$(this).parent().attr("class") || !prev || prev.length == 0 || prev.attr("class").indexOf("div-no-task-item") == -1) {
bl = false;
}
});
if (bl) {
taskItem.each(function () {
var item = $(this);
var prev = item.parent().find("div:eq(" + (k + 1) + ")");
if (prev.length > 0) {
item.after('<div class="div-no-task-item"></div>');
item.wrap("<div></div>");
prev.after(item.parent().html());
prev.remove();
item.parent().remove();
}
});
} }
}
});
} //end for taskCodeList
//去空
table.find("td").each(function () {
var td = $(this);
while (true) {
var div = td.find("div:last");
if (div.attr("class").indexOf("div-no-task-item") != -1) {
div.remove();
}
else {
break;
}
}
});
} //end 优化显示 //日期td单击双击
table.find("td").each(function () {
var td = $(this);
var grayDay = td.attr('class').indexOf('td-gray') == -1;
td.click(function () {
if (grayDay) {
if (td.attr("class").indexOf("td-selected") != -1) {
td.removeClass("td-selected");
} else {
$(".td-selected").removeClass("td-selected");
td.addClass("td-selected");
}
}
});
td.dblclick(function () {
if (grayDay) {
add(td.attr("day"));
}
});
}); //任务单击双击
$(".div-task-item").each(function () {
var taskItemDiv = $(this);
var taskCode = taskItemDiv.attr("taskCode");
taskItemDiv.click(function (evt) {
$(".div-task-item").removeClass("highlight-task");
table.find("div[taskCode='" + taskCode + "']").addClass("highlight-task");
evt.stopPropagation();
});
taskItemDiv.dblclick(function (evt) {
evt.stopPropagation();
});
});
} //创建新计划
function add(day) {
data.list.push({ id: '15', taskCode: '000', title: '测试新增', content: '测试内容', year: 2016, month: 1, day: parseInt(day) });
createTaskCodeList(data, taskCodeList)
var scrollTop = $("#div-days").scrollTop();
$("#month").change();
$("#div-days").scrollTop(scrollTop);
} //今天
function gotoToday() {
var today = new Date();
$("#year").val(today.getFullYear());
$("#month").val(today.getMonth() + 1);
$("#month").change();
var top = $(".td-today").position().top - $(".table-days").position().top;
var div = $("#div-days").scrollTop(top);
var div = $(".td-selected").removeClass("td-selected");
} //上月
function preMonth() {
var year = $("#year").val();
var month = $("#month").val();
if (month == 1) {
$("#year").val(parseInt(year) - 1);
$("#month").val(12);
} else {
$("#month").val(parseInt(month) - 1);
}
$("#month").change();
$("#div-days").scrollTop($(window).height());
} //下月
function nextMonth() {
var year = $("#year").val();
var month = $("#month").val();
if (month == 12) {
$("#year").val(parseInt(year) + 1);
$("#month").val(1);
} else {
$("#month").val(parseInt(month) + 1);
}
$("#month").change();
$("#div-days").scrollTop(0);
} //获取task索引
function getTaskIndex(taskCodeList, taskCode) {
var pos = 0;
for (var i = 0; i < taskCodeList.length; i++) {
if (taskCodeList[i] == taskCode) {
break;
}
pos++;
}
return pos;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="padding: 5px;">
<div style="padding: 10px;">
<input type="button" value="今天" onclick="gotoToday()" />
<input type="button" value="<" onclick="preMonth()" />
<select id="year" name="year">
<option value="2017">2017</option>
<option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
</select>
年
<select id="month" name="month">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
月
<input type="button" value=">" onclick="nextMonth()" />
</div>
<div style="margin-top: 5px;">
<table class="table-title" cellpadding="0" cellspacing="0">
<tr>
<td>星期一</td>
<td>星期二</td>
<td>星期三</td>
<td>星期四</td>
<td>星期五</td>
<td>星期六</td>
<td>星期日</td>
</tr>
</table>
</div>
<div id="div-days" style="height: 350px; overflow: auto; margin-top: -1px; border-bottom: solid 1px #ddd;">
<table id="table-days" class="table-days" cellpadding="0" cellspacing="0">
</table>
</div>
</div>
</form>
<script type="text/javascript">
//获取当月天数
function getDaysOfMonth(year, month) {
var d = new Date(year, month, 0);
return d.getDate();
} //获取前一个月天数
function getDaysOfPreMonth(year, month) {
if (month == 1) {
month = 12;
year = year - 1;
}
else {
month = month - 1;
}
var d = new Date(year, month, 0);
return d.getDate();
} //获取当天星期数(0到6)
function getWeek(year, month, day) {
var d = new Date(year, month - 1, day);
return d.getDay();
} //颜色集合
var myColor = [
'ccddff',
'ccffdd',
'eeccff',
'eeffcc',
'ffccee',
'ffeecc'
]; //获取颜色
function getColor(taskCodeList, taskCode) {
var pos = 0;
for (var i = 0; i < taskCodeList.length; i++) {
if (taskCodeList[i] == taskCode) {
break;
}
pos++;
if (pos > myColor.length - 1) {
pos = 0;
}
}
return myColor[pos];
}
</script>
</body>
</html>
效果图:

JS实现日程安排 日程安排插件的更多相关文章
- Chocolat.js – 响应式的 jQuery Lightbox 插件
Chocolat.js 使您能够显示一个或多个图像在同一页面上.给用户展示一组图片缩略图,可以显示全页或块.Chocolat.js 可以很好地处理所有主要的浏览器.它在下面这些浏览器测试通过:IE7+ ...
- 【原创】cs+html+js+css模式(六):改造ajax.js,从原来的原生态js修改为依赖于jquery插件
由于原有的ajax可能在性能上,对于jquery的支持不够并且不够方便,开发人员使用的时候需要知道我们内部指定的后缀文件的设置,基于这个前提我们进行了js的改造 // 使用闭包开发插件 ( ...
- js 控制Div循环显示 非插件版
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- ImageLightbox.js – 响应式的图片 Lightbox 插件
ImageLightbox.js 是一款很简洁的用于显示图片灯箱效果(Lightbox)的插件,没有字幕,导航按钮或默认背景.如果默认功能不够用的话,你可以很容易地自定义 JavaScript 函数扩 ...
- KoaHub平台基于Node.js开发的Koa 连接支付宝插件代码信息详情
KoaHub平台基于Node.js开发的Koa 链接支付宝插件代码信息详情 easy-alipay alipay payment & notification APIs easy-alipay ...
- baguetteBox.js - 简单易用的 lightbox 插件
baguetteBox.js 是一个简单和易于使用的响应式的图像 Lightbox 插件,支持滑动手势在移动设备上使用.纯 JavaScript 实现,不依赖第三方库和插件,赶紧来体验吧. 在线演示 ...
- jquery.chosen.js下拉选择框美化插件项目实例
由于之前使用的bootstrap-select插件是建立在bootstrap基础上的,实际使用到项目中的时候,与我们使用的ace-admin(基于bootstrap)存在样式冲突,导致下拉框的样式发生 ...
- PHP 多图上传,图片批量上传插件,webuploader.js,百度文件上传插件
PHP 多图上传,图片批量上传插件,webuploader.js,百度文件上传插件(案例教程) WebUploader作用:http://fex.baidu.com/webuploader/gett ...
- 【原创】JS文件替换神器--Chrome ReRes插件
本文仅供学习交流使用,如侵立删! JS文件替换神器--Chrome ReRes插件 ReRes插件安装配置 ReRes项目官方地址:https://github.com/annnhan/ReRes 谷 ...
随机推荐
- 在GitHub注册账户的过程
(1)第一步:首先起一个属于自己用户的名字(username),用户名字只能包含字母数字的字符或者单个连字符,不能只用单个连字符开始或者结束(only contain alphanumeric cha ...
- 爱上MVC3系列~开发一个站点地图(俗称面包屑)
回到目录 原来早在webform控件时代就有了SiteMap这个东西,而进行MVC时代后,我们也希望有这样一个东西,它为我们提供了不少方便,如很方便的实现页面导航的内容修改,页面导航的样式换肤等. 我 ...
- H5常用代码:适配方案3
在H5项目中有一种常见的宣传页,就是那种整屏整屏的,带着炫丽进场动画的移动宣传页,不仅是一种欣赏也起到了很大宣传作用. 对于这种整屏的适配,前面通过视口的兼容处理也是可以做到的,但是在窄屏下会在上下有 ...
- Android笔记——Android内部类
Java语言允许在类中再定义类,这种在其它类内部定义的类就叫内部类.内部类又分为:常规内部类.局部内部类.匿名内部类和静态嵌套类四种.我们内部类的知识在Android手机开发中经常用到. 一.常规内部 ...
- Struts2学习笔记 - HelloWorld总结
相信网上已经有很多关于struts2的HelloWorld可参考,我这里就不重复了,没个学struts2的人都会做过很多个HelloWorld,而我这里就总结一下一个简单的HelloWorld 我在一 ...
- wampserver中Apache启动不了的问题
今天晚上安装了wampserver,启动后,右下角的图表橙色,绿色才代表服务启动成功,到底是什么原因导致不能成功启动呢? 网上查资料,说可能是端口冲突,也可能是网络TCP/IP的设置有关系,我设置TC ...
- JS原生第二篇 (帅哥)
1.1 Javascript 作用 1. 网页特效 2. 用户交互 3. 表单验证 Js 就是可以用来控制 结构 和 样式 . 1.2 体验js 认识常用的三个输出语句. 都属于 ...
- BrowserSync前端调试工具使用
上次介绍了一款DebugGap移动端调试工具DebugGap推荐.但是这几天使用了之后感觉还是有些不足,尤其是里面的调试工具虽然和Chrome里面的调试长的很像,但是多少有些不同,使用起来还是不太方便 ...
- AJAX大文件切割上传以及带进度条。
分块传输的原理就是利用HTML5新增的文件slice截取函数. 代码如下: html: <input id="f" type="file" name=&q ...
- 最简单的可取消多选效果(以从水果篮中挑选水果为例)【jsDEMO】
[功能说明] 最简单的可取消多选效果(以从水果篮中挑选水果为例) [html代码说明] <div class="box" id="box"> < ...