javascript月历,js获取年月
JavaScript月历问题
var gMonths=new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
“专业、务实、高效、创新、把客户的事当成自己的事”是我们每一个人一直以来坚持追求的企业文化。 创新互联是您可以信赖的网站建设服务商、专业的互联网服务提供商! 专注于成都网站设计、成都网站制作、软件开发、设计服务业务。我们始终坚持以客户需求为导向,结合用户体验与视觉传达,提供有针对性的项目解决方案,提供专业性的建议,创新互联建站将不断地超越自我,追逐市场,引领市场!
var WeekDay=new Array("日","一","二","三","四","五","六");
var strToday="今天";
var strYear="年";
var strMonth="月";
var strDay="日";
var splitChar="-";
var startYear=2010;
var endYear=2020;
var dayTdHeight=12;
var dayTdTextSize=12;
var gcNotCurMonth="#E0E0E0";
var gcRestDay="#FF0000";
var gcWorkDay="#444444";
var gcMouseOver="#79D0FF";
var gcMouseOut="#F4F4F4";
var gcToday="#444444";
var gcTodayMouseOver="#6699FF";
var gcTodayMouseOut="#79D0FF";
var gdCtrl=new Object();
var goSelectTag=new Array();
var gdCurDate=new Date();
var giYear=gdCurDate.getFullYear();
var giMonth=gdCurDate.getMonth()+1;
var giDay=gdCurDate.getDate();
function $(){var elements=new Array();for(var i=0;iarguments.length;i++) {var element=arguments[i];if(typeof(arguments[i])=='string'){element=document.getElementById(arguments[i]);}if(arguments.length==1){return element;}elements.Push(element);}return elements;}
Array.prototype.Push=function(){var startLength=this.length;for(var i=0;iarguments.length;i++){this[startLength+i]=arguments[i];}return this.length;}
String.prototype.HexToDec=function(){return parseInt(this,16);}
String.prototype.cleanBlank=function(){return this.isEmpty()?"":this.replace(/\s/g,"");}
function checkColor(){var color_tmp=(arguments[0]+"").replace(/\s/g,"").toUpperCase();var model_tmp1=arguments[1].toUpperCase();var model_tmp2="rgb("+arguments[1].substring(1,3).HexToDec()+","+arguments[1].substring(1,3).HexToDec()+","+arguments[1].substring(5).HexToDec()+")";model_tmp2=model_tmp2.toUpperCase();if(color_tmp==model_tmp1 ||color_tmp==model_tmp2){return true;}return false;}
function $V(){return $(arguments[0]).value;}
function fPopCalendar(evt,popCtrl,dateCtrl){evt.cancelBubble=true;gdCtrl=dateCtrl;fSetYearMon(giYear,giMonth);var point=fGetXY(popCtrl);with($("calendardiv").style){left=point.x+"px";top=(point.y+popCtrl.offsetHeight+1)+"px";visibility='visible';zindex='99';position='absolute';}$("calendardiv").focus();}
function fSetDate(iYear,iMonth,iDay){var iMonthNew=new String(iMonth);var iDayNew=new String(iDay);if(iMonthNew.length2){iMonthNew="0"+iMonthNew;}if(iDayNew.length2){iDayNew="0"+iDayNew;}gdCtrl.value=iYear+splitChar+iMonthNew+splitChar+iDayNew;fHideCalendar();}
function fHideCalendar(){$("calendardiv").style.visibility="hidden";for(var i=0;igoSelectTag.length;i++){goSelectTag[i].style.visibility="visible";}goSelectTag.length=0;}
function fSetSelected(){var iOffset=0;var iYear=parseInt($("tbSelYear").value);var iMonth=parseInt($("tbSelMonth").value);var aCell=$("cellText"+arguments[0]);aCell.bgColor=gcMouseOut;with(aCell){var iDay=parseInt(innerHTML);if(checkColor(style.color,gcNotCurMonth)){iOffset=(innerHTML10)?-1:1;}iMonth+=iOffset;if(iMonth1){iYear--;iMonth=12;}else if(iMonth12){iYear++;iMonth=1;}}fSetDate(iYear,iMonth,iDay);}
function Point(iX,iY){this.x=iX;this.y=iY;}
function fBuildCal(iYear,iMonth){var aMonth=new Array();for(var i=1;i7;i++){aMonth[i]=new Array(i);}var dCalDate=new Date(iYear,iMonth-1,1);var iDayOfFirst=dCalDate.getDay();var iDaysInMonth=new Date(iYear,iMonth,0).getDate();var iOffsetLast=new Date(iYear,iMonth-1,0).getDate()-iDayOfFirst+1;var iDate=1;var iNext=1;for(var d=0;d7;d++){aMonth[1][d]=(diDayOfFirst)?(iOffsetLast+d)*(-1):iDate++;}for(var w=2;w7;w++){for(var d=0;d7;d++){aMonth[w][d]=(iDate=iDaysInMonth)?iDate++:(iNext++)*(-1);}}return aMonth;}
function fDrawCal(iYear,iMonth,iCellHeight,iDateTextSize){var colorTD=" bgcolor='"+gcMouseOut+"' bordercolor='"+gcMouseOut+"'";var styleTD=" valign='middle' align='center' style='height:"+iCellHeight+"px;font-weight:bolder;font-size:"+iDateTextSize+"px;";var dateCal="";dateCal+="tr";for(var i=0;i7;i++){dateCal+="td"+colorTD+styleTD+"color:#990099'"+WeekDay[i]+"/td";}dateCal+="/tr";for(var w=1;w7;w++){dateCal+="tr";for(var d=0;d7;d++){var tmpid=w+""+d;dateCal+="td"+styleTD+"cursor:pointer;' onclick='fSetSelected("+tmpid+")'";dateCal+="span id='cellText"+tmpid+"'/span";dateCal+="/td";}dateCal+="/tr";}return dateCal;}
function fUpdateCal(iYear,iMonth){var myMonth=fBuildCal(iYear,iMonth);var i=0;for(var w=1;w7;w++){for(var d=0;d7;d++){with($("cellText"+w+""+d)){parentNode.bgColor=gcMouseOut;parentNode.borderColor=gcMouseOut;parentNode.onmouseover=function(){this.bgColor=gcMouseOver;};parentNode.onmouseout=function(){this.bgColor=gcMouseOut;};if(myMonth[w][d]0){style.color=gcNotCurMonth;innerHTML=Math.abs(myMonth[w][d]);}else{style.color=((d==0)||(d==6))?gcRestDay:gcWorkDay;innerHTML=myMonth[w][d];if(iYear==giYear iMonth==giMonth myMonth[w][d]==giDay){style.color=gcToday;parentNode.bgColor=gcTodayMouseOut;parentNode.onmouseover=function(){this.bgColor=gcTodayMouseOver;};parentNode.onmouseout=function(){this.bgColor=gcTodayMouseOut;};}}}}}}
function fSetYearMon(iYear,iMon){$("tbSelMonth").options[iMon-1].selected=true;for(var i=0;i$("tbSelYear").length;i++){if($("tbSelYear").options[i].value==iYear){$("tbSelYear").options[i].selected=true;}}fUpdateCal(iYear,iMon);}
function fPrevMonth(){var iMon=$("tbSelMonth").value;var iYear=$("tbSelYear").value;if(--iMon1){iMon=12;iYear--;}fSetYearMon(iYear,iMon);}
function fNextMonth(){var iMon=$("tbSelMonth").value;var iYear=$("tbSelYear").value;if(++iMon12){iMon=1;iYear++;}fSetYearMon(iYear,iMon);}
function fGetXY(aTag){var oTmp=aTag;var pt=new Point(0,0);do{pt.x+=oTmp.offsetLeft;pt.y+=oTmp.offsetTop;oTmp=oTmp.offsetParent;}while(oTmp.tagName.toUpperCase()!="BODY");return pt;}
function getDateDiv(){var noSelectForIE="";var noSelectForFireFox="";if(document.all){noSelectForIE="onselectstart='return false;'";}else{noSelectForFireFox="-moz-user-select:none;";}var dateDiv="";dateDiv+="div id='calendardiv' onclick='event.cancelBubble=true' "+noSelectForIE+" style='"+noSelectForFireFox+"position:absolute;z-index:99;visibility:hidden;border:1px solid #999999;'";dateDiv+="table border='0' bgcolor='#E0E0E0' cellpadding='1' cellspacing='1' ";dateDiv+="tr";dateDiv+="tdinput type='button' id='PrevMonth' value='' style='height:20px;width:20px;font-weight:bolder;' onclick='fPrevMonth()'";dateDiv+="/tdtdselect id='tbSelYear' style='border:1px solid;' onchange='fUpdateCal($V(\"tbSelYear\"),$V(\"tbSelMonth\"))'";for(var i=startYear;iendYear;i++){dateDiv+="option value='"+i+"'"+i+strYear+"/option";}dateDiv+="/select/tdtd";dateDiv+="select id='tbSelMonth' style='border:1px solid;' onchange='fUpdateCal($V(\"tbSelYear\"),$V(\"tbSelMonth\"))'";for(var i=0;i12;i++){dateDiv+="option value='"+(i+1)+"'"+gMonths[i]+"/option";}dateDiv+="/select/tdtd";dateDiv+="input type='button' id='NextMonth' value='' style='height:20px;width:20px;font-weight:bolder;' onclick='fNextMonth()'";dateDiv+="/td";dateDiv+="/trtr";dateDiv+="td align='center' colspan='4'";dateDiv+="div style='background-color:#cccccc'table width='100%' border='0' cellpadding='3' cellspacing='1'";dateDiv+=fDrawCal(giYear,giMonth,dayTdHeight,dayTdTextSize);dateDiv+="/table/div";dateDiv+="/td";dateDiv+="/trtrtd align='center' colspan='4' nowrap";dateDiv+="span style='cursor:pointer;font-weight:bolder;' onclick='fSetDate(giYear,giMonth,giDay)' onmouseover='this.style.color=\""+gcMouseOver+"\"' onmouseout='this.style.color=\"#000000\"'"+strToday+":"+giYear+strYear+giMonth+strMonth+giDay+strDay+"/span";dateDiv+="/tr/tr";dateDiv+="/table/div";return dateDiv;}
with(document){onclick=fHideCalendar;write(getDateDiv());}
td 费用发生日期:*/td
tdlabel
input type="text" name="date" style="border:1px solid #999;" onClick="fPopCalendar(event,this,this)" onFocus="this.select()" readonly="readonly" /
*
/label/td
javascript 获取输入出阳历和阴历日期时间
script language="JavaScript"
!--
var bsYear;
var bsDate;
var bsWeek;
var arrLen=8; //数组长度
var sValue=0; //当年的秒数
var dayiy=0; //当年第几天
var miy=0; //月份的下标
var iyear=0; //年份标记
var dayim=0; //当月第几天
var spd=86400; //每天的秒数
var year1999="30;29;29;30;29;29;30;29;30;30;30;29"; //354
var year2000="30;30;29;29;30;29;29;30;29;30;30;29"; //354
var year2001="30;30;29;30;29;30;29;29;30;29;30;29;30"; //384
var year2002="30;30;29;30;29;30;29;29;30;29;30;29"; //354
var year2003="30;30;29;30;30;29;30;29;29;30;29;30"; //355
var year2004="29;30;29;30;30;29;30;29;30;29;30;29;30"; //384
var year2005="29;30;29;30;29;30;30;29;30;29;30;29"; //354
var year2006="30;29;30;29;30;30;29;29;30;30;29;29;30";
var month1999="正月;二月;三月;四月;五月;六月;七月;八月;九月;十月;十一月;十二月"
var month2001="正月;二月;三月;四月;闰四月;五月;六月;七月;八月;九月;十月;十一月;十二月"
var month2004="正月;二月;闰二月;三月;四月;五月;六月;七月;八月;九月;十月;十一月;十二月"
var month2006="正月;二月;三月;四月;五月;六月;七月;闰七月;八月;九月;十月;十一月;十二月"
var Dn="初一;初二;初三;初四;初五;初六;初七;初八;初九;初十;十一;十二;十三;十四;十五;十六;十七;十八;十九;二十;廿一;廿二;廿三;廿四;廿五;廿六;廿七;廿八;廿九;三十";
var Ys=new Array(arrLen);
Ys[0]=919094400;Ys[1]=949680000;Ys[2]=980265600;
Ys[3]=1013443200;Ys[4]=1044028800;Ys[5]=1074700800;
Ys[6]=1107878400;Ys[7]=1138464000;
var Yn=new Array(arrLen); //农历年的名称
Yn[0]="己卯年";Yn[1]="庚辰年"; Yn[2]="辛巳年";
Yn[3]="壬午年";Yn[4]="癸未年";Yn[5]="甲申年";
Yn[6]="乙酉年"; Yn[7]="丙戌年";
var D=new Date();
var yy=D.getYear();
var mm=D.getMonth()+1;
var dd=D.getDate();
var ww=D.getDay();
if (ww==0) ww="font color=RED星期日";
if (ww==1) ww="星期一";
if (ww==2) ww="星期二";
if (ww==3) ww="星期三";
if (ww==4) ww="星期四";
if (ww==5) ww="星期五";
if (ww==6) ww="font color=RED星期六";
ww=ww;
var ss=parseInt(D.getTime() / 1000);
if (yy100) yy="19"+yy;
for (I=0;IarrLen;I++)
if (ss=Ys[I])...{
iyear=I;
sValue=ss-Ys[I]; //当年的秒数
}
dayiy=parseInt(sValue/spd)+1; //当年的天数
var dpm=year1999;
if (iyear==1) dpm=year2000;
if (iyear==2) dpm=year2001;
if (iyear==3) dpm=year2002;
if (iyear==4) dpm=year2003;
if (iyear==5) dpm=year2004;
if (iyear==6) dpm=year2005;
if (iyear==7) dpm=year2006;
dpm=dpm.split(";");
var Mn=month1999;
if (iyear==2) Mn=month2001;
if (iyear==5) Mn=month2004;
if (iyear==7) Mn=month2006;
Mn=Mn.split(";");
var Dn="初一;初二;初三;初四;初五;初六;初七;初八;初九;初十;十一;十二;十三;十四;十五;十六;十七;十八;十九;二十;廿一;廿二;廿三;廿四;廿五;廿六;廿七;廿八;廿九;三十";
Dn=Dn.split(";");
dayim=dayiy;
var total=new Array(13);
total[0]=parseInt(dpm[0]);
for (I=1;Idpm.length-1;I++) total[I]=parseInt(dpm[I])+total[I-1];
for (I=dpm.length-1;I0;I--)
if (dayimtotal[I-1])...{
dayim=dayim-total[I-1];
miy=I;
}
bsWeek=ww;
bsDate=yy+"年"+mm+"月";
bsDate2=dd;
bsYear="农历"+Yn[iyear];
bsYear2=Mn[miy]+Dn[dayim-1];
if (ss=Ys[7]||ssYs[0]) bsYear=Yn[7];
function CAL(){
document.write("table border='1' cellspacing='3' width='90' bordercolor='#000000' bgcolor='#FFFFFF' height='110' cellpadding='2'");
document.write("trtd align='center'bfont color=#008040"+bsDate+"/fontbrfont face='Arial' size='6' color=#FF8040"+bsDate2+"/fontbrfont color=#008040span style='FONT-SIZE: 10.5pt'");
document.write(bsWeek+"/spanbr"+"br/bfont color=#9B4E00");
document.write(bsYear+"br"+bsYear2+"/td/tr/table");
}
//--
/script
script language="javascript"CAL();/script
求一款js做的时间日历控件?
这是我找到的一个js做的日历,不知道是不是你要的,里面有包含时间,其实在日历里面加时间也是比较简单的,只要调用DATE的方法就可以了,希望对你有用。下面是代码段,效果图附上。
html
head
SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"
//定义月历函数
function calendar() {
var today = new Date(); //创建日期对象
year = today.getYear(); //读取年份
thisDay = today.getDate(); //读取当前日
//创建每月天数数组
var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
//如果是闰年,2月份的天数为29天
if (((year % 4 == 0) (year % 100 != 0)) || (year % 400 == 0)) monthDays[1] = 29;
daysOfCurrentMonth = monthDays[today.getMonth()]; //从每月天数数组中读取当月的天数
firstDay = today;//复制日期对象
firstDay.setDate(1); //设置日期对象firstDay的日为1号
startDay = firstDay.getDay(); //确定当月第一天是星期几
//定义周日和月份中文名数组
var dayNames = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
var monthNames = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
//创建日期对象
var newDate = new Date();
//创建表格
document.write("TABLE BORDER='0' CELLSPACING='0' CELLPADDING='2' ALIGN='CENTER' BGCOLOR='#0080FF'")
document.write("TRTDtable border='0' cellspacing='1' cellpadding='2' bgcolor='#88FF99'");
document.write("TRth colspan='7' bgcolor='#C8E3FF'");
//显示当前日期和周日
document.writeln("FONT STYLE='font-size:9pt;Color:#FF0000'" + newDate.getYear() + "年" + monthNames[newDate.getMonth()] + " " + newDate.getDate() + "日 " + dayNames[newDate.getDay()] + "/FONT");
//显示月历表头
document.writeln("/TH/TRTRTH BGCOLOR='#0080FF'FONT STYLE='font-size:9pt;Color:White'日/FONT/TH");
document.writeln("th bgcolor='#0080FF'FONT STYLE='font-size:9pt;Color:White'一/FONT/TH");
document.writeln("TH BGCOLOR='#0080FF'FONT STYLE='font-size:9pt;Color:White'二/FONT/TH");
document.writeln("TH BGCOLOR='#0080FF'FONT STYLE='font-size:9pt;Color:White'三/FONT/TH");
document.writeln("TH BGCOLOR='#0080FF'FONT STYLE='font-size:9pt;Color:White'四/FONT/TH");
document.writeln("TH BGCOLOR='#0080FF'FONT STYLE='font-size:9pt;Color:White'五/FONT/TH");
document.writeln("TH BGCOLOR='#0080FF'FONT STYLE='font-size:9pt;Color:White'六/FONT/TH");
document.writeln("/TRTR");
//显示每月前面的"空日"
column = 0;
for (i=0; istartDay; i++) {
document.writeln(" TDFONT STYLE='font-size:9pt' /FONT/TD");
column++;
}
//如果是当前日就突出显示(红色),否则正常显示(黑色)
for (i=1; i=daysOfCurrentMonth; i++) {
if (i == thisDay) {
document.writeln("/TDTD ALIGN='CENTER'FONT STYLE='font-size:9pt;Color:#ff0000'B")
}
else {
document.writeln("/TDTD BGCOLOR='#88FF99' ALIGN='CENTER'FONT STYLE='font-size:9pt;font-family:Arial;font-weight:bold;Color:#000000'");
}
document.writeln(i);
if (i == thisDay) document.writeln("/FONT/TD")
column++;
if (column == 7) {
document.writeln("TR");
column = 0;
}
}
document.writeln("TRTD COLSPAN='7' ALIGN='CENTER' VALIGN='TOP' BGCOLOR='#0080FF'")
document.writeln("FORM NAME='time' onSubmit='0'FONT STYLE='font-size:9pt;Color:#ffffff'")
//显示当前时间
document.writeln("当前时间:INPUT TYPE='Text' NAME='textbox' ALIGN='TOP'/FONT/TD/TR/TABLE")
document.writeln("/TD/TR/TABLE/FORM");
}
/SCRIPT
SCRIPT LANGUAGE="JavaScript"
//初始化控制变量
var timerID = null;
var timerRunning = false;
//定义时间显示函数
function stoptime (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;}
//定义显示时间函数
function showtime () {
var newDate = new Date();
var hours = newDate.getHours();
var minutes = newDate.getMinutes();
var seconds = newDate.getSeconds()
var timeValue = " " + ((hours 12) ? hours -12 :hours)
timeValue += ((minutes 10) ? ":0" : ":") + minutes
timeValue += ((seconds 10) ? ":0" : ":") + seconds
timeValue += (hours = 12) ? " 下午 " : " 上午 "
document.time.textbox.value = timeValue;
timerID = setTimeout("showtime()",1000);//设置超时,使时间动态显示
timerRunning = true;}
//显示当前时间
function starttime () {
stoptime();
showtime();}
/SCRIPT
/head
BODY onLoad="starttime()" TEXT="#000000" TOPMARGIN="0"
script language="JavaScript" type="text/javascript"
calendar(); //显示月历
/script
/BODY
/html
请教下各位,通过javascript来实现 有某年第几周 得到 这周的开始日期 和结束日期,怎么写啊?
html
head
title用JavaScript编写动态月历/title
script type="text/javascript"
!--
//函数是每个month对象的方法
function getFirstDay(theYear, theMonth){
var firstDate = new Date(theYear,theMonth,1);
return firstDate.getDay();
}
//每个月的天数
function getMonthLen(theYear, theMonth) {
var oneHour = 1000 * 60 * 60;
var oneDay = oneHour * 24;
var thisMonth = new Date(theYear, theMonth, 1);
var nextMonth = new Date(theYear, theMonth + 1, 1);
var len = Math.ceil((nextMonth.getTime() - thisMonth.getTime() - oneHour)/oneDay);
return len;
}
//修正Y2K问题
function getY2KYear(today) {
var yr = today.getYear();
return ((yr 100) ? yr + 1900 : yr);
}
function populateFields(form) {
//为用户最后选择初始化变量
var theMonth = form.chooseMonth.selectedIndex;
var theYear = form.chooseYear.options[form.chooseYear.selectedIndex].value;
//初始化与日期相关的变量
//选择月份的第一天
var firstDay = getFirstDay(theYear, theMonth);
//下列循环所需要的TD...\/TD标记的总数
var howMany = getMonthLen(theYear, theMonth);
//设置年份和月份
form.oneMonth.value = theYear+"年"+theMonths[theMonth];
//填充表域
for (var i = 0; i 42; i++) {
if (i firstDay || i = (howMany + firstDay)) {
// 在实际日期的前后清空表域
form.oneDay[i].value = "";
} else {
// 输入日期值
form.oneDay[i].value = i - firstDay + 1;
}
}
}
//--
/script
/head
body
centerh1生成的月历(动态)/h1/center
hr /
script type="text/javascript"
!--
//初始化变量
//创建month对象名数组
theMonths = new Array("1月", "2月", "3月", "4月", "5月","6月",
"7月", "8月", "9月", "10月", "11月", "12月");
// 填充表域
var oneField = "input type='text' name='oneDay' size='2' onfocus=''";
//开始组合HTML表格
var content = "formcentertable border='1'";
//在月历顶部显示年份和月份
content += "trth colspan='7'input type='text'name='oneMonth'\/th\/tr";
//列头的星期
content += "trth 日 \/thth 一 \/thth 二 \/th";
content += "th 三 \/thth 四 \/thth 五 \/th";
content += "th 六 \/th\/trtr";
//布局6行
for (var i = 1; i 43; i++) {
content += "td align='middle'" + oneField + "\/td";
if (i % 7 == 0) {
content += "\/trtr";
}
}
content += "\/table";
// 向文档写整个表的HTML
document.write(content);
//--
/script
select name="chooseYear"
option value="2003" selected="selected"2003年/option
option value="2004"2004年/option
option value="2005"2005年/option
option value="2006"2006年/option
option value="2007"2007年/option
option value="2008"2008年/option
option value="2009"2009年/option
option value="2010"2010年/option
option value="2011"2011年/option
/select
select name="chooseMonth"
option value="January" selected="selected"1月/option
option value="February"2月/option
option value="March"3月/option
option value="April"4月/option
option value="May"5月/option
option value="June"6月/option
option value="July"7月/option
option value="August"8月/option
option value="September"9月/option
option value="October"10月/option
option value="November"11月/option
option value="December"12月/option
/select
br /
input type="button" name="updater" value="更新月历" onclick="populateFields(this.form)" /
/form
/body
/html
用javascript实现日历,高手帮忙
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
title网页特效|Linkweb.cn/Js|---一个很漂亮实用的日历/title
SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"
//创建一个数组,用于存放每个月的天数
function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11)
{
this[0] = m0;
this[1] = m1;
this[2] = m2;
this[3] = m3;
this[4] = m4;
this[5] = m5;
this[6] = m6;
this[7] = m7;
this[8] = m8;
this[9] = m9;
this[10] = m10;
this[11] = m11;
}
//实现月历
function calendar() {
var monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec";
var today = new Date();
var thisDay;
var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
year = today.getYear() +1900;
thisDay = today.getDate();
if (((year % 4 == 0) (year % 100 != 0)) || (year % 400 == 0)) monthDays[1] = 29;
nDays = monthDays[today.getMonth()];
firstDay = today;
firstDay.setDate(1);
testMe = firstDay.getDate();
if (testMe == 2) firstDay.setDate(0);
startDay = firstDay.getDay();
document.write("div id='rili' style='position:absolute;width:140px;left:300px;top:100px;'")
document.write("TABLE width='217' BORDER='0' CELLSPACING='0' CELLPADDING='2' BGCOLOR='#0080FF'")
document.write("TRTDtable border='0' cellspacing='1' cellpadding='2' bgcolor='Silver'");
document.write("TRth colspan='7' bgcolor='#C8E3FF'");
var dayNames = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
var monthNames = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
var now = new Date();
document.writeln("FONT STYLE='font-size:9pt;Color:#330099'" + "公元 " + now.getYear() + "年" + monthNames[now.getMonth()] + " " + now.getDate() + "日 " + dayNames[now.getDay()] + "/FONT");
document.writeln("/TH/TRTRTH BGCOLOR='#0080FF'FONT STYLE='font-size:9pt;Color:White'日/FONT/TH");
document.writeln("th bgcolor='#0080FF'FONT STYLE='font-size:9pt;Color:White'一/FONT/TH");
document.writeln("TH BGCOLOR='#0080FF'FONT STYLE='font-size:9pt;Color:White'二/FONT/TH");
document.writeln("TH BGCOLOR='#0080FF'FONT STYLE='font-size:9pt;Color:White'三/FONT/TH");
document.writeln("TH BGCOLOR='#0080FF'FONT STYLE='font-size:9pt;Color:White'四/FONT/TH");
document.writeln("TH BGCOLOR='#0080FF'FONT STYLE='font-size:9pt;Color:White'五/FONT/TH");
document.writeln("TH BGCOLOR='#0080FF'FONT STYLE='font-size:9pt;Color:White'六/FONT/TH");
document.writeln("/TRTR");
column = 0;
for (i=0; istartDay; i++) {
document.writeln("\nTDFONT STYLE='font-size:9pt' /FONT/TD");
column++;
}
for (i=1; i=nDays; i++) {
if (i == thisDay) {
document.writeln("/TDTD ALIGN='CENTER' BGCOLOR='#FF8040'FONT STYLE='font-size:9pt;Color:#ffffff'B")
}
else {
document.writeln("/TDTD BGCOLOR='#FFFFFF' ALIGN='CENTER'FONT STYLE='font-size:9pt;font-family:Arial;font-weight:bold;Color:#330066'");
}
document.writeln(i);
if (i == thisDay) document.writeln("/FONT/TD")
column++;
if (column == 7) {
document.writeln("TR");
column = 0;
}
}
document.writeln("TRTD COLSPAN='7' ALIGN='CENTER' VALIGN='TOP' BGCOLOR='#0080FF'")
document.writeln("FORM NAME='clock' onSubmit='0'FONT STYLE='font-size:9pt;Color:#ffffff'")
document.writeln("现在时间:INPUT TYPE='Text' NAME='face' ALIGN='TOP'/FONT/FORM/TD/TR/TABLE")
document.writeln("/TD/TR/TABLE/div");
}
/SCRIPT
SCRIPT LANGUAGE="JavaScript"
var timerID = null;
var timerRunning = false;
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;}
//显示当前时间
function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = " " + ((hours 12) ? hours -12 :hours)
timeValue += ((minutes 10) ? ":0" : ":") + minutes
timeValue += ((seconds 10) ? ":0" : ":") + seconds
timeValue += (hours = 12) ? " 下午 " : " 上午 "
document.clock.face.value = timeValue;
timerID = setTimeout("showtime()",1000);//设置超时,使时间动态显示
timerRunning = true;}
function startclock () {
stopclock();
showtime();}
/SCRIPT
/head
body onLoad="startclock(); timerONE=window.setTimeout"
script language="JavaScript" type="text/javascript"
!--
calendar();
//--
/script
/body
/html
位置和颜色可以自己改
如何把js中的日历显示改成月历?
如果要选择到月份。劝你不要用js了多麻烦。两个下拉列表 年-月。
当前题目:javascript月历,js获取年月
路径分享:http://myzitong.com/article/dsgpede.html