页面
<div class="un1">
<h2>服务档期</h2>
<div class="date-panel" style="height: 525px;">
<div class="bars">
<a href="javascript:void (0);" id="monthStart" class="b-l"></a>
<span class="b-c" id="monthInfo"></span>
<a href="javascript:void (0);" id="monthNext" class="b-r"></a>
</div>
<input type="hidden" id="shopId" value="34782e16-53d1-4c1c-b573-e82b0eae5d87" />
<input type="hidden" id="base" value="http://sc.izhaowo.com" />
<input type="hidden" id="schTname" value="ZHUCHIREN001" />
<table id="dateTable" class="picTable">
<tbody>
<tr>
<th>日</th>
<th>一</th>
<th>二</th>
<th>三</th>
<th>四</th>
<th>五</th>
<th>六</th>
</tr>
<tr>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
</tr>
<tr>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
</tr>
<tr>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
</tr>
<tr>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
</tr>
<tr>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
</tr>
<tr>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
<td id="home" valign="top"><span></span></td>
</tr>
</tbody>
</table>
</div>
</div> js代码:
/**
* Created by dengxu on 14-6-6.
*/
var today = new Date();
var thisMonth = today.getMonth()+;
var thisYear= today.getFullYear(); //日历
window.onload = function(){
viewSchedule();
} function viewSchedule (){
var table = document.getElementById("dateTable");
var yearS = document.getElementById("monthInfo");
var dayNum = ;
var fullMonth = thisMonth;
if(fullMonth<){
fullMonth = ""+(fullMonth);
}
yearS.innerHTML = thisYear+'年'+(fullMonth)+'月'; //初始化日期
var aTD = table.getElementsByTagName("TD");
//获取本月一号
today.setFullYear(thisYear);
today.setMonth(thisMonth-);
today.setDate();
//日期
dayNum = monthDay(thisYear,thisMonth);
//获取上一个月有多少天
var exDayNum = monthDay(thisYear,thisMonth-);
if(today.getDay()==) {
var i = ;
for (i; i < dayNum; i++) {
aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(i + )+'</span>';
}
var k = ;
for (i; i < ; i++) {
aTD[i].innerHTML = '<span id="'+(thisMonth+)+'">'+(k)+'</span>';
k++;
}
}else if(today.getDay()==) {
var n = exDayNum - ;
var i = ;
for (n; n <= exDayNum; n++) {
aTD[i].innerHTML = '<span id="'+(thisMonth-)+'">'+(n)+'</span>';
i++;
}
var j = ;
for (j; j < dayNum; j++) {
aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(j + )+'</span>';
i++;
}
var k = ;
for(i;i<;i++){
aTD[i].innerHTML = '<span id="'+(thisMonth+)+'">'+(k)+'</span>';
k++;
}
}else if(today.getDay()==) {
var n = exDayNum - ;
var i = ;
for (n; n <= exDayNum; n++) {
aTD[i].innerHTML = '<span id="'+(thisMonth-)+'">'+(n)+'</span>';
i++;
}
var j = ;
for (j; j < dayNum; j++) {
aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(j + )+'</span>';
i++;
}
var k = ;
for(i;i<;i++){
aTD[i].innerHTML = '<span id="'+(thisMonth+)+'">'+(k)+'</span>';
k++;
}
}else if(today.getDay()==) {
var n = exDayNum - ;
var i = ;
for (n; n <= exDayNum; n++) {
aTD[i].innerHTML = '<span id="'+(thisMonth-)+'">'+(n)+'</span>';
i++;
}
var j = ;
for (j; j < dayNum; j++) {
aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(j + )+'</span>';
i++;
}
var k = ;
for(i;i<;i++){
aTD[i].innerHTML = '<span id="'+(thisMonth+)+'">'+(k)+'</span>';
k++;
}
}else if(today.getDay()==) {
var n = exDayNum - ;
var i = ;
for (n; n <= exDayNum; n++) {
aTD[i].innerHTML = '<span id="'+(thisMonth-)+'">'+(n)+'</span>';
i++;
}
var j = ;
for (j; j < dayNum; j++) {
aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(j + )+'</span>';
i++;
}
var k = ;
for(i;i<;i++){
aTD[i].innerHTML = '<span id="'+(thisMonth+)+'">'+(k)+'</span>';
k++;
}
}else if(today.getDay()==) {
var n = exDayNum - ;
var i = ;
for (n; n <= exDayNum; n++) {
aTD[i].innerHTML = '<span id="'+(thisMonth-)+'">'+(n)+'</span>';
i++;
}
var j = ;
for (j; j < dayNum; j++) {
aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(j + )+'</span>';
i++;
}
var k = ;
for(i;i<;i++){
aTD[i].innerHTML = '<span id="'+(thisMonth+)+'">'+(k)+'</span>';
k++;
}
}else if(today.getDay()==) {
var n = exDayNum-;
var i = ;
for(n;n<=exDayNum;n++){
aTD[i].innerHTML = '<span id="'+(thisMonth-)+'">'+(n)+'</span>';
i++;
}
var j = ;
for(j;j<dayNum;j++){
aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(j + )+'</span>';
i++;
}
var k = ;
for(i;i<;i++){
aTD[i].innerHTML = '<span id="'+(thisMonth+)+'">'+(k)+'</span>';
k++;
}
}
//上一个月
function previous (){
var thisM = thisMonth;
var thisY= thisYear;
if(thisM==){
thisM = ;
thisY = thisY-;
}else{
thisM = thisM-;
}
thisYear = thisY;
thisMonth = thisM;
viewSchedule(); } //下一个月
function next (){
var thisM = thisMonth;
var thisY= thisYear;
if(thisM==){
thisM = ;
thisY = thisY+;
}else{
thisM = thisM+;
}
thisYear = thisY;
thisMonth = thisM;
viewSchedule(); } //是否为闰年
function isLeapYear(year){
if(year%== && year%!=){
return true;
}
else{
if(year%==){
return true;
}
else{
return false;
}
}
} //判断每月有几天
function monthDay(year,month){
if(month== || month== || month== || month== || month== || month== || month== || month==){
return ;
}else if(month== || month== || month== || month==){
return ;
}else if(month== && isLeapYear(year)){
return ;
}else{
return ;
}
} function nowDay(){
var monthStart = document.getElementById("monthStart");
var monthNext = document.getElementById("monthNext"); monthStart.onclick = function(){
previous();
}
monthNext.onclick = function(){
next();
}
}
nowDay();
setSchedule(table);
} //格式化日期,
function formatDate(date,format){
var paddNum = function(num){
num += "";
return num.replace(/^(\d)$/,"0$1");
}
//指定格式字符
var cfg = {
yyyy : date.getFullYear() //年 : 4位
,yy : date.getFullYear().toString().substring()//年 : 2位
,M : date.getMonth() + //月 : 如果1位的时候不补0
,MM : paddNum(date.getMonth() + ) //月 : 如果1位的时候补0
,d : date.getDate() //日 : 如果1位的时候不补0
,dd : paddNum(date.getDate())//日 : 如果1位的时候补0
,hh : date.getHours() //时
,HH : paddNum(date.getHours()) //时
,mm : paddNum(date.getMinutes()) //分
,ss : date.getSeconds() //秒
}
format || (format = "yyyy-MM-dd hh:mm:ss");
return format.replace(/([a-z])(\)*/ig,function(m){return cfg[m];});
} ////替换所有
//String.prototype.replaceAll = function(s1,s2) {
// return this.replace(new RegExp(s1, "gm"), s2); //g全局
//} var tdValue = ""; //设置档期
function setSchedule(obj){
var shopId = document.getElementById("shopId").value;
var base = document.getElementById("base").value;
//档期时间集合
var fullMonth = thisMonth;
if(fullMonth<){
fullMonth = ""+(fullMonth);
}
var scheduleList = "";
$.ajax({
url:base+'/schedule/doSchedule',
type:'post',
dateType:'json',
data:'shopId='+shopId+"&date="+thisYear+"-"+fullMonth+"-03",
timeout:*,
success:function(data){
//档期
var schedule = data.schedules;
//当前月份
var fullMonth;
var thisTd = obj.getElementsByTagName("TD"); for(var k = ;k<thisTd.length;k++){
var day = thisTd[k].getElementsByTagName("span")[].innerHTML;
//用于显示到日历上面
var day2 = thisTd[k].getElementsByTagName("span")[].innerHTML; fullMonth = thisTd[k].getElementsByTagName("span")[].id;
var tdHTML = thisTd[k];
if(day<){
day = ""+(day);
}
if(fullMonth<){
fullMonth = ""+(fullMonth);
} //今天
var thisDay = thisYear+"-"+fullMonth+"-"+day;
for(var i = ;i<schedule.length;i++){
for(var j = ;j<schedule[i].scheuleEvts.length;j++){
var thisDate = null;
if(schedule[i].workerSchedule.scheduleType==){
thisDate = formatDate(new Date(schedule[i].scheuleEvts[j].stime),"yyyy-MM-dd"); if(thisDay==thisDate){
tdHTML.innerHTML = "";
var serviceType = '<p>服务类型:'+schedule[i].scheuleEvts[j].serviceName+'</p>';
if($("#schTname").val() == "CEHUASHI001"){
serviceType = "";
}
if(schedule[i].scheuleEvts.length==||(j+)==schedule[i].scheuleEvts.length){
tdValue += '<p>预订人:'+schedule[i].scheuleEvts[j].contactName.substring(,)+'**</p>'+
serviceType+
'<p>服务价格:'+schedule[i].scheuleEvts[j].servicePrice/+'</p>'+
'<p>服务时间:'+formatDate(new Date(schedule[i].scheuleEvts[j].stime),"yyyy-MM-dd")+" - "+formatDateForHour(new Date(schedule[i].scheuleEvts[j].stime).getHours(),new Date(schedule[i].scheuleEvts[j].etime).getHours())+'</p> '+
'<p style="padding-left: 60px;">'+schedule[i].scheuleEvts[j].address.replace(",","-")+'</p> ';
}else{
tdHTML.getElementsByTagName("span")[].className = "cur";
tdHTML.innerHTML = tdHTML.innerHTML + '<i class="cur2">已预订</i>';
tdValue += '<p>预订人:'+schedule[i].scheuleEvts[j].contactName.substring(,)+'**</p>'+
serviceType+
'<p>服务价格:'+schedule[i].scheuleEvts[j].servicePrice/+'</p>'+
'<p>服务时间:'+formatDate(new Date(schedule[i].scheuleEvts[j].stime),"yyyy-MM-dd")+" - "+formatDateForHour(new Date(schedule[i].scheuleEvts[j].stime).getHours(),new Date(schedule[i].scheuleEvts[j].etime).getHours())+'</p> '+
'<p style="padding-left: 60px;">'+schedule[i].scheuleEvts[j].address.replace(",","-")+'</p> '+
'<p style="border-bottom:1px dashed #ddd; margin:5px 0px; *height:1px;"></p>';
}
}
}
}
if(schedule[i].workerSchedule.scheduleType==){
thisDate = formatDate(new Date(schedule[i].workerSchedule.date),"yyyy-MM-dd");
if(thisDay==thisDate){
//if(tdHTML.childNodes[0].nodeName == "SPAN"){
// day = thisTd[k].getElementsByTagName("span")[0].innerHTML;
// tdHTML.innerHTML = '<span class="gray" id="'+fullMonth+'">'+day+'</span>'
//
//}
tdHTML.getElementsByTagName("span")[].className = "cur";
tdHTML.getElementsByTagName("span")[].style.background = "#bfbfbf";
tdHTML.innerHTML = tdHTML.innerHTML + '<i class="cur2">今日忙</i>';
} } if(tdHTML.innerHTML==""){
tdHTML.innerHTML ='<span id="'+fullMonth+day+'" class="cur">'+day2+'</span>' +
'<i class="cur2">已预订</i>'+
'<div style="display: none;left:65px; top:-50px;" id="info'+fullMonth+day+'" class="buyInfo">'+tdValue+'</div>';
}
tdValue = "";
}
} },
error:function(){
// alert("对不起,请稍后再试!");
}
});
} function formatDateForHour(st,et){
if (st >= && et <= ) {
return "午宴";
}else if(st >= && et <= ) {
return "晚宴";
}else{
return "全天";
}
} 另一个js: var today = new Date();
var thisMonth = today.getMonth()+;
var thisYear= today.getFullYear(); //日历
window.onload = function(){
viewSchedule();
} function viewSchedule (){
var table = document.getElementById("dateTable");
var yearS = document.getElementById("monthInfo");
var dayNum = ;
var fullMonth = thisMonth;
if(fullMonth<){
fullMonth = ""+(fullMonth);
}
yearS.innerHTML = thisYear+'年'+(fullMonth)+'月'; //初始化日期
var aTD = table.getElementsByTagName("TD");
//获取本月一号
today.setFullYear(thisYear);
today.setMonth(thisMonth-);
today.setDate();
//日期
dayNum = monthDay(thisYear, thisMonth);
//获取当前月第一天是礼拜几
var monthfirstday = today.getDay();
for (var j = ; j < ; j++) {
aTD[j].innerHTML = '';
}
for (var i = ; i < dayNum; i++) {
aTD[i + monthfirstday].innerHTML = '<span id="' + (i + ) + '">' + (i + ) + '</span>';
}
//获取上一个月有多少天
var exDayNum = monthDay(thisYear, thisMonth - );
//if(today.getDay()==0) {
// var i = 0;
// for (i; i < dayNum; i++) {
// aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(i + 1)+'</span>';
// }
// var k = 1;
// for (i; i < 42; i++) {
// //aTD[i].innerHTML = '<span id="'+(thisMonth+1)+'">'+(k)+'</span>';
// k++;
// }
//}else if(today.getDay()==1) {
// var n = exDayNum - 0;
// var i = 0;
// for (n; n <= exDayNum; n++) {
// //aTD[i].innerHTML = '<span id="'+(thisMonth-1)+'">'+(n)+'</span>';
// i++;
// }
// var j = 0;
// for (j; j < dayNum; j++) {
// aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(j + 1)+'</span>';
// i++;
// }
// var k = 1;
// for(i;i<42;i++){
// //aTD[i].innerHTML = '<span id="'+(thisMonth+1)+'">'+(k)+'</span>';
// k++;
// }
//}else if(today.getDay()==2) {
// var n = exDayNum - 1;
// var i = 0;
// for (n; n <= exDayNum; n++) {
// //aTD[i].innerHTML = '<span id="'+(thisMonth-1)+'">'+(n)+'</span>';
// i++;
// }
// var j = 0;
// for (j; j < dayNum; j++) {
// aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(j + 1)+'</span>';
// i++;
// }
// var k = 1;
// for(i;i<42;i++){
// // aTD[i].innerHTML = '<span id="'+(thisMonth+1)+'">'+(k)+'</span>';
// k++;
// }
//}else if(today.getDay()==3) {
// var n = exDayNum - 2;
// var i = 0;
// for (n; n <= exDayNum; n++) {
// // aTD[i].innerHTML = '<span id="'+(thisMonth-1)+'">'+(n)+'</span>';
// i++;
// }
// var j = 0;
// for (j; j < dayNum; j++) {
// aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(j + 1)+'</span>';
// i++;
// }
// var k = 1;
// for(i;i<42;i++){
// // aTD[i].innerHTML = '<span id="'+(thisMonth+1)+'">'+(k)+'</span>';
// k++;
// }
//}else if(today.getDay()==4) {
// var n = exDayNum - 3;
// var i = 0;
// for (n; n <= exDayNum; n++) {
// // aTD[i].innerHTML = '<span id="'+(thisMonth-1)+'">'+(n)+'</span>';
// i++;
// }
// var j = 0;
// for (j; j < dayNum; j++) {
// aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(j + 1)+'</span>';
// i++;
// }
// var k = 1;
// for(i;i<42;i++){
// //aTD[i].innerHTML = '<span id="'+(thisMonth+1)+'">'+(k)+'</span>';
// k++;
// }
//}else if(today.getDay()==5) {
// var n = exDayNum - 4;
// var i = 0;
// for (n; n <= exDayNum; n++) {
// // aTD[i].innerHTML = '<span id="'+(thisMonth-1)+'">'+(n)+'</span>';
// i++;
// }
// var j = 0;
// for (j; j < dayNum; j++) {
// aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(j + 1)+'</span>';
// i++;
// }
// var k = 1;
// for(i;i<42;i++){
// // aTD[i].innerHTML = '<span id="'+(thisMonth+1)+'">'+(k)+'</span>';
// k++;
// }
//}else if(today.getDay()==6) {
// var n = exDayNum-5;
// var i = 0;
// for(n;n<=exDayNum;n++){
// //aTD[i].innerHTML = '<span id="'+(thisMonth-1)+'">'+(n)+'</span>';
// i++;
// }
// var j = 0;
// for(j;j<dayNum;j++){
// aTD[i].innerHTML = '<span id="'+thisMonth+'">'+(j + 1)+'</span>';
// i++;
// }
// var k = 1;
// for(i;i<42;i++){
// //aTD[i].innerHTML = '<span id="'+(thisMonth+1)+'">'+(k)+'</span>';
// k++;
// }
//}
//上一个月
function previous (){
var thisM = thisMonth;
var thisY= thisYear;
if(thisM==){
thisM = ;
thisY = thisY-;
}else{
thisM = thisM-;
}
thisYear = thisY;
thisMonth = thisM;
viewSchedule(); } //下一个月
function next (){
var thisM = thisMonth;
var thisY= thisYear;
if(thisM==){
thisM = ;
thisY = thisY+;
}else{
thisM = thisM+;
}
thisYear = thisY;
thisMonth = thisM;
viewSchedule(); } //是否为闰年
function isLeapYear(year){
if(year%== && year%!=){
return true;
}
else{
if(year%==){
return true;
}
else{
return false;
}
}
} //判断每月有几天
function monthDay(year,month){
if(month== || month== || month== || month== || month== || month== || month== || month==){
return ;
}else if(month== || month== || month== || month==){
return ;
}else if(month== && isLeapYear(year)){
return ;
}else{
return ;
}
} function nowDay(){
var monthStart = document.getElementById("monthStart");
var monthNext = document.getElementById("monthNext"); monthStart.onclick = function(){
previous();
}
monthNext.onclick = function(){
next();
}
}
nowDay();
setSchedule(table);
//$("#svrcitys").html(table);
} //格式化日期,
function formatDate(date,format){
var paddNum = function(num){
num += "";
return num.replace(/^(\d)$/,"0$1");
}
//指定格式字符
var cfg = {
yyyy : date.getFullYear() //年 : 4位
,yy : date.getFullYear().toString().substring()//年 : 2位
,M : date.getMonth() + //月 : 如果1位的时候不补0
,MM : paddNum(date.getMonth() + ) //月 : 如果1位的时候补0
,d : date.getDate() //日 : 如果1位的时候不补0
,dd : paddNum(date.getDate())//日 : 如果1位的时候补0
,hh : date.getHours() //时
,HH : paddNum(date.getHours()) //时
,mm : paddNum(date.getMinutes()) //分
,ss : date.getSeconds() //秒
}
format || (format = "yyyy-MM-dd hh:mm:ss");
return format.replace(/([a-z])(\)*/ig,function(m){return cfg[m];});
}
var tdValue = ""; //设置档期
function setSchedule(obj) {
var pUID = $("#pUID").val();
//var shopId = document.getElementById("shopId").value;
//var base = document.getElementById("base").value;
//档期时间集合
var fullMonth = thisMonth;
if (fullMonth < ) {
fullMonth = "" + (fullMonth);
}
var scheduleList = "";
var parameter = 'action=usercalendar&uid=' + pUID + '&thisYear=' + thisYear + '&fullMonth=' + fullMonth;
$.ajax({
type: "Post",
async: true,
cache: false,
url: "/ashx/web/web.ashx",
data: parameter,
dataType: "json",
success: function (data) {
//档期
// var schedule = data.schedules;
//当前月份
var fullMonth;
var thisTd = obj.getElementsByTagName("TD");
//for (var k = 0; k < thisTd.length; k++) {
// var day = thisTd[k].getElementsByTagName("span")[0].innerHTML;
// alert(day);
// //用于显示到日历上面
// var day2 = thisTd[k].getElementsByTagName("span")[0].innerHTML;
// fullMonth = thisTd[k].getElementsByTagName("span")[0].id;
// var tdHTML = thisTd[k];
// if (day < 10) {
// day = "0" + (day);
// }
// if (fullMonth < 10) {
// fullMonth = "0" + (fullMonth);
// }
// //今天
//var thisDay = thisYear + "-" + fullMonth + "-" + day;
// if (data.ObjDataList.length > 0) {
$.each(data.ObjDataList, function (i, item) {
var thisDate = item.MTSDate;
var d = new Date(thisDate);
var MTSState = item.MTSState;
var AMIsOrder = item.AMIsOrder;
var PMIsOrder = item.PMIsOrder;
var tday = d.getDate(); //if (thisDay == thisDate) {
//判断状态
//var busy = "";
//if (item.AMISBusy == 1 && item.PMISBusy == 1) {
// busy = "今日忙"; //}
//else {
// if (item.AMISBusy == 1) {
// busy = "上午忙";
// $("#" + tday).addClass("cur");
// $("#" + tday).css({ background: "#bfbfbf" });
// $("#" + tday).append('<i class="cur2">' + busy + '</i>');
// }
// else if (item.PMISBusy == 1) {
// busy = "下午忙";
// $("#" + tday).addClass("cur");
// $("#" + tday).css({ background: "#bfbfbf" });
// $("#" + tday).append('<i class="cur2">' + busy + '</i>');
// }
//}
//var yuding = "";
//if (AMIsOrder == 1 && PMIsOrder == 1) {
// yuding = "已预订";
//}
//else {
// if (AMIsOrder ==1)
// {
// yuding = "AM已约";
// }
// else if (PMIsOrder ==1)
// {
// yuding = "PM已约";
// }
//}
if (AMIsOrder == && item.MTSAM == "" && PMIsOrder == && item.MTSPM == "")
{
$("#" + tday).addClass("cur");
$("#" + tday).css({ background: "#bfbfbf" });
$("#" + tday).append('<i class="cur2">今日忙</i>');
}
else if (AMIsOrder == && item.MTSAM != "" && PMIsOrder == && item.MTSPM != "")
{
$("#" + tday).addClass("cur");
$("#" + tday).append('<i class="cur2">已预订</i>');
}
else if (AMIsOrder == && item.MTSAM == "")
{
$("#" + tday).addClass("cur");
$("#" + tday).css({ background: "#bfbfbf" });
$("#" + tday).append('<i class="cur2">上午忙</i>');
}
else if (PMIsOrder == && item.MTSPM == "") {
$("#" + tday).addClass("cur");
$("#" + tday).css({ background: "#bfbfbf" });
$("#" + tday).append('<i class="cur2">下午忙</i>');
}
else if (AMIsOrder == && item.MTSAM != "")
{
$("#" + tday).addClass("cur");
$("#" + tday).append('<i class="cur2">AM已约</i>');
}
else if (PMIsOrder == && item.MTSPM != "") {
$("#" + tday).addClass("cur");
$("#" + tday).append('<i class="cur2">PM已约</i>');
} //if (MTSState == 1) {
// //tdHTML.getElementsByTagName("span")[0].className = "cur";
// //tdHTML.getElementsByTagName("span")[0].style.background = "#bfbfbf";
// //tdHTML.innerHTML = tdHTML.innerHTML + '<i class="cur2">今日忙</i>';
// $("#" + tday).addClass("cur");
// $("#" + tday).css({ background: "#bfbfbf" });
// if (AMIsOrder == 1 && PMIsOrder == 1) {
// $("#" + tday).append('<i class="cur2">今日忙</i>');
// }
// else {
// if (AMIsOrder == 1)
// {
// $("#" + tday).append('<i class="cur2">上午忙</i>');
// }
// else if (PMIsOrder ==1)
// {
// $("#" + tday).append('<i class="cur2">下午忙</i>');
// }
// } //}
//else if (MTSState == 2) {
// //tdHTML.getElementsByTagName("span")[0].className = "cur";
// //tdHTML.innerHTML = tdHTML.innerHTML + '<i class="cur2">已预订</i>';
// $("#" + tday).addClass("cur");
// if (AMIsOrder == 1 && PMIsOrder == 1) {
// $("#" + tday).append('<i class="cur2">已预订</i>');
// }
// else {
// if (AMIsOrder == 1) {
// $("#" + tday).append('<i class="cur2">AM已约</i>');
// }
// else if (PMIsOrder == 1) {
// $("#" + tday).append('<i class="cur2">PM已约</i>');
// }
// } //}
//else {
// //tdHTML.getElementsByTagName("span")[0].className = "cur";
// //tdHTML.getElementsByTagName("span")[0].style.background = "#bfbfbf";
// //tdHTML.innerHTML = tdHTML.innerHTML + '<i class="cur2">今日忙</i>';
// $("#" + tday).addClass("cur");
// $("#" + tday).css({ background: "#bfbfbf" });
// $("#" + tday).append('<i class="cur2">今日忙</i>');
//}
// }
});
// }
//}
}
});
}
<!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=gb2312" />
<title>blog式日历控件_www.jb51.net_脚本之家</title>
</head>
<body>
<script type="text/javascript">
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
}; var Class = {
create: function () {
return function () {
this.initialize.apply(this, arguments);
}
}
} Object.extend = function (destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
} var Calendar = Class.create();
Calendar.prototype = {
initialize: function (container, options) {
this.Container = $(container);//容器(table结构)
this.Days = [];//日期对象列表 this.SetOptions(options); this.Year = this.options.Year;
this.Month = this.options.Month;
this.SelectDay = this.options.SelectDay ? new Date(this.options.SelectDay) : null;
this.onSelectDay = this.options.onSelectDay;
this.onToday = this.options.onToday;
this.onFinish = this.options.onFinish; this.Draw();
},
//设置默认属性
SetOptions: function (options) {
this.options = {//默认值
Year: new Date().getFullYear(),//显示年
Month: new Date().getMonth() + ,//显示月
SelectDay: null,//选择日期
onSelectDay: function () { },//在选择日期触发
onToday: function () { },//在当天日期触发
onFinish: function () { }//日历画完后触发
};
Object.extend(this.options, options || {});
},
//上一个月
PreMonth: function () {
//先取得上一个月的日期对象
var d = new Date(this.Year, this.Month - , );
//再设置属性
this.Year = d.getFullYear();
this.Month = d.getMonth() + ;
//重新画日历
this.Draw();
},
//下一个月
NextMonth: function () {
var d = new Date(this.Year, this.Month, );
this.Year = d.getFullYear();
this.Month = d.getMonth() + ;
this.Draw();
},
//画日历
Draw: function () {
//用来保存日期列表
var arr = [];
//用当月第一天在一周中的日期值作为当月离第一天的天数
for (var i = , firstDay = new Date(this.Year, this.Month - , ).getDay() ; i <= firstDay; i++) { arr.push(" "); }
//用当月最后一天在一个月中的日期值作为当月的天数
for (var i = , monthDay = new Date(this.Year, this.Month, ).getDate() ; i <= monthDay; i++) { arr.push(i); } var frag = document.createDocumentFragment(); this.Days = []; while (arr.length > ) {
//每个星期插入一个tr
var row = document.createElement("tr");
//每个星期有7天
for (var i = ; i <= ; i++) {
var cell = document.createElement("td");
cell.innerHTML = " "; if (arr.length > ) {
var d = arr.shift();
cell.innerHTML = d;
if (d > ) {
this.Days[d] = cell;
//判断是否今日
if (this.IsSame(new Date(this.Year, this.Month - , d), new Date())) { this.onToday(cell); }
//判断是否选择日期
if (this.SelectDay && this.IsSame(new Date(this.Year, this.Month - , d), this.SelectDay)) { this.onSelectDay(cell); }
}
}
row.appendChild(cell);
}
frag.appendChild(row);
} //先清空内容再插入(ie的table不能用innerHTML)
while (this.Container.hasChildNodes()) { this.Container.removeChild(this.Container.firstChild); }
this.Container.appendChild(frag); this.onFinish();
},
//判断是否同一日
IsSame: function (d1, d2) {
return (d1.getFullYear() == d2.getFullYear() && d1.getMonth() == d2.getMonth() && d1.getDate() == d2.getDate());
}
}; </script>
<style type="text/css">
.Calendar {
font-family: Verdana;
font-size: 12px;
background-color: #e0ecf9;
text-align: center;
width: 200px;
height: 160px;
padding: 10px;
line-height: .5em;
} .Calendar a {
color: #1e5494;
} .Calendar table {
width: %;
border: ;
} .Calendar table thead {
color: #acacac;
} .Calendar table td {
font-size: 11px;
padding: 1px;
} #idCalendarPre {
cursor: pointer;
float: left;
padding-right: 5px;
} #idCalendarNext {
cursor: pointer;
float: right;
padding-right: 5px;
} #idCalendar td.onToday {
font-weight: bold;
color: #C60;
} #idCalendar td.onSelect {
font-weight: bold;
}
</style>
<div class="Calendar">
<div id="idCalendarPre"><<</div>
<div id="idCalendarNext">>></div>
<span id="idCalendarYear"></span>年 <span id="idCalendarMonth"></span>月
<table cellspacing="">
<thead>
<tr>
<td>日</td>
<td>一</td>
<td>二</td>
<td>三</td>
<td>四</td>
<td>五</td>
<td>六</td>
</tr>
</thead>
<tbody id="idCalendar"></tbody>
</table>
</div>
<script language="JavaScript"> var cale = new Calendar("idCalendar", {
SelectDay: new Date().setDate(),
onSelectDay: function (o) { o.className = "onSelect"; },
onToday: function (o) { o.className = "onToday"; },
onFinish: function () {
$("idCalendarYear").innerHTML = this.Year; $("idCalendarMonth").innerHTML = this.Month;
var flag = [, , ];
for (var i = , len = flag.length; i < len; i++) {
this.Days[flag[i]].innerHTML = "<a href='javascript:void(0);' onclick=\"alert('日期是:" + this.Year + "/" + this.Month + "/" + flag[i] + "');return false;\">" + flag[i] + "</a>";
}
}
}); $("idCalendarPre").onclick = function () { cale.PreMonth(); }
$("idCalendarNext").onclick = function () { cale.NextMonth(); } </script>
</body>
</html>

js日历算法的更多相关文章

  1. 简洁JS 日历控件 支持日期和月份选择

    原文出处 以下这个JS日历控件是我的闲暇之余自己编写的,所有的代码全部在IE7/IE8/Firefox下面测试通过, 而且可以解决被iframe层遮盖的问题.现在只提供两种风格(简洁版和古典版)和两种 ...

  2. 百度的js日历

    <title>百度的Js日历,值得一看</title> <style> body,td,.p1,.p2,.i{font-family:arial} body{mar ...

  3. JS日历控件优化(增加时分秒)

    JS日历控件优化      在今年7月份时候 写了一篇关于 "JS日历控件" 的文章 , 当时只支持 年月日 的日历控件,现在优化如下:      1. 在原基础上 支持 yyyy ...

  4. Js 日期选择,可以的一个页面中重复使用本JS日历,兼容IE及火狐等主流浏览器,而且界面简洁、美观,操作体验也不错。

    <html> <head> <title>Js日期选择器并自动加入到输入框中</title> <meta http-equiv="con ...

  5. JS日历控件集合----附效果图、源代码

    http://www.cnblogs.com/yank/archive/2008/08/14/1267746.html 在进行开发的过程中,经常需要输入时间,特别是在进行查询.统计的时候,时间限定更为 ...

  6. js日历学习

    <!DOCTYPE html><html><head><title>自己写的JS日历,适合学习</title><script src= ...

  7. 简洁js日历控件的使用

    往Web工程添加纯js日历控件 在网上找到了DatePicker.js(http://www.cnblogs.com/shenyixin/archive/2013/03/11/2954156.html ...

  8. JS日历控件 灵活设置: 精确的时分秒.

     在今年7月份时候 写了一篇关于 "JS日历控件" 的文章 , 当时仅仅支持 年月日 的日历控件,如今优化例如以下:      1. 在原基础上 支持 yyyy-mm-dd 的年月 ...

  9. js的 算法 和 数据结构

    js的 算法 1.对一个对象数组按照对象某个属性进行排序  : https://www.cnblogs.com/webcabana/p/7460038.html 在做公交的项目中就碰到过这种算法问题, ...

随机推荐

  1. 洛谷 P1025 & [NOIP2001提高组] 数的划分(搜索剪枝)

    题目链接 https://www.luogu.org/problemnew/show/P1025 解题思路 一道简单的dfs题,但是需要剪枝,否则会TLE. 我们用dfs(a,u,num)来表示上一个 ...

  2. python eval( ) 使用详解

      1.解析表达式 (表达式是str类型)----最常用     a = 12     b = "联播"     result1 = eval(a+3)        # resu ...

  3. java、javaw和javaws的区别

    java.javaw和javaws的区别: 首先,所有的这些都是java的启动装置,java.exe经常使用,当使用命令行输出到window的时候,会有java.exe进程,通过任务管理器可以看到.通 ...

  4. JS中的reduce函数

    海纳百川,有容乃大 定义: reduce()方法接受一个函数作为累加器,数组中的每个值(从左向右)开始缩减,最终计算为一个值.对空数组是不会执行回调函数的. 案例: 计算数组总和: var num = ...

  5. 2019-9-2-win10-uwp-兴趣线

    title author date CreateTime categories win10 uwp 兴趣线 lindexi 2019-09-02 12:57:38 +0800 2018-2-13 17 ...

  6. 基于ZYNQ XC7Z045 FFG 900的高性能计算模块

    一.板卡概述 本板卡基于Xilinx公司的FPGA XC7Z045 FFG 9000 芯片, 该平台为设计和验证应用程序提供了一个完整的开发平台.该平台使设计师能够更加简单进行高性能的原型设计,并且通 ...

  7. php pdo_mysql扩展安装

    本文内容是以 CentOS 为例,红帽系列的 Linux 方法应该都是如此,下面就详细说明步骤,在这里严重鄙视哪些内容??隆⑺档脑悠咴影说挠泄 PDO 编译安装的文章. 1.进入 PHP 的软件包 p ...

  8. Ubuntu简单安装kafka及使用

    参考地址:https://www.jianshu.com/p/d0e630c8f4ae 一.下载 kafka 二进制安装包 下载地址: http://kafka.apache.org/download ...

  9. [BZOJ3626] [LNOI2014] LCA 离线 树链剖分

    题面 考虑到询问的\(l..r,z\)具有可减性,考虑把询问差分掉,拆成\(r,z\)和\(l-1,z\). 显然这些LCA一定在\(z\)到根的路径上.下面的问题就是怎么统计. 考虑不是那么暴力的暴 ...

  10. PhpStorm中如何使用database工具

    环境:ubuntu18.4 mysql5.7 一. 打开database 1.选择View—>Tool Windows—>Database单击打开. 2.新增数据连接 选择 “+”—> ...