我想在选今天时显示日期的月份和日期如果是个位数的话前面加个0. |
|
| 作者:fabregs 来源:不详 发布时间:2008/07/21 发布人:admin | |
| "htmloDayTable+=" onmouseover=CalendarCellsMsOver("+this.instanceName+")"; |
/// Today Button
htmloButton="
htmloButton+=" htmloButton+=" onclick=CalendarTodayClick("+this.instanceName+")>"+this.oBtnTodayTitle+" "
htmloButton+=" htmloButton+="onclick=clearInput("+this.instanceName+")>"+this.oBtnCleanTitle+" "
htmloButton+=" htmloButton+=" onclick=CalendarCancel("+this.instanceName+")>"+this.oBtnCancelTitle+" "
htmloButton+="
/// All
htmlAll=htmlAll+htmloYear+htmloMonth+htmloDayTable+htmloButton+"
document.write(htmlAll);
this.Fill();
}
function CalendarFill() ///
{
var sMonth,sYear,sWeekDay,sToday,oTable,currRow,MaxDay,sDaySn,sIndex,rowIndex,cellIndex,oSelectMonth,oSelectYear
sMonth=this.currDate.getMonth();
//dt = new Date();
//alert(dt);
sYear=this.currDate.getFullYear();
sWeekDay=(new Date(sYear,sMonth,1)).getDay();
sToday=this.currDate.getDate();
//oTable=document.all[this.sTABLEID];
oTable = document.getElementById(this.sTABLEID);
currRow=oTable.rows[1];
MaxDay=CalendarGetMaxDay(sYear,sMonth);
//oSelectMonth=document.all[this.sMONTHID]
oSelectMonth = document.getElementById(this.sMONTHID);
oSelectMonth.selectedIndex=sMonth;
//oSelectYear=document.all[this.sYEARID]
oSelectYear = document.getElementById(this.sYEARID);
//alert(oSelectYear.options[0].value);
for(i=0;i
if(parseInt(oSelectYear.options.innerHTML=""+sDaySn+"";
this.oPreviousCell=currRow.cells[sIndex];
}
else
{
currRow.cells[sIndex].innerHTML=sDaySn;
currRow.cells[sIndex].style.color="#666666";
}
CalendarCellSetCss(0,currRow.cells[sIndex]);
}
for(rowIndex=2;rowIndex<=6;rowIndex++)
{
if(sDaySn>MaxDay)break;
currRow=oTable.rows[rowIndex];
for(cellIndex=0;cellIndex
if(sDaySn==sToday)
{
currRow.cells[cellIndex].innerHTML=""+sDaySn+"";
this.oPreviousCell=currRow.cells[cellIndex];
}
else
{
currRow.cells[cellIndex].innerHTML=sDaySn;
currRow.cells[cellIndex].style.color="#666666";
}
CalendarCellSetCss(0,currRow.cells[cellIndex]);
sDaySn++;
if(sDaySn>MaxDay)break;
}
}
glbObjPointer.value = sYear + "-" + (sMonth+1)+ "-" + sToday;
if(!this.instanceName) {
document.getElementById(this.sDIVID).style.display="block";
}else {
document.getElementById(this.sDIVID).style.display="none";
}
//
}
function CalendarRestore() /// Clear Data
{
var oTable
//oTable=document.all[this.sTABLEID]
oTable = document.getElementById(this.sTABLEID);
for(i=1;i
for(j=0;j
}
}
}
function CalendarRefresh(newDate) ///
{
this.currDate=newDate;
this.Restore();
this.Fill();
}
function CalendarCellsMsOver(oInstance) /// Cell MouseOver
{
var myCell
myCell=event.srcElement; //????
CalendarCellSetCss(0,oInstance.oPreviousCell);
if(myCell)
{
CalendarCellSetCss(1,myCell);
oInstance.oPreviousCell=myCell;
}
}
function CalendarCellsMsOut(oInstance) ////// Cell MouseOut
{
var myCell
myCell=event.srcElement; //??????
CalendarCellSetCss(0,myCell);
}
function CalendarCellsClick(oCell,oInstance)
{
//alert(oCell.innerText);
var sDay,sMonth,sYear,newDate
sYear=oInstance.currDate.getFullYear();
//alert(sYear);
//alert('dddddddddddddd');
sMonth=oInstance.currDate.getMonth();
//alert(sMonth);
sDay=oInstance.currDate.getDate();
//alert('|'+ oCell.innerHTML + '|');
if (document.all){
txt = oCell.innerText;
}else{
txt = oCell.innerHTML;
if ( txt == ' ' ){
txt = " ";
}
else if(txt.indexOf('') != -1){
txt = txt.substring(txt.indexOf('')+3,txt.length);
txt = txt.substring(0,txt.indexOf(''));
}
}
if(txt != " ")
{
sDay=txt;//parseInt(oCell.innerText);
if(sDay!=oInstance.currDate.getDate())
{
newDate=new Date(sYear,sMonth,sDay);
oInstance.Refresh(newDate);
}
}
sDateString=sYear+oInstance.separator+CalendarDblNum(sMonth+1)+oInstance.separator+CalendarDblNum(sDay); ///return
sDateString
//alert(sDateString);
if(oInstance.oTaget.tagName=="INPUT")
{
oInstance.oTaget.value=sDateString;
}
//document.all[oInstance.sDIVID].style.display="none";
document.getElementById(oInstance.sDIVID).style.display="none";
}
function clearInput(oInstance){
if(oInstance.oTaget.tagName=="INPUT")
{
oInstance.oTaget.value="";
}
CalendarCancel(oInstance);
}
function CalendarYearChange(oInstance) /// Year Change
{
var sDay,sMonth,sYear,newDate
sDay=oInstance.currDate.getDate();
sMonth=oInstance.currDate.getMonth();
//sYear=document.all[oInstance.sYEARID].value
sYear = document.getElementById(oInstance.sYEARID).value
newDate=new Date(sYear,sMonth,sDay);
oInstance.Refresh(newDate);
}
function CalendarMonthChange(oInstance) /// Month Change
{
var sDay,sMonth,sYear,newDate
sDay=oInstance.currDate.getDate();
//sMonth=document.all[oInstance.sMONTHID].value
sMonth=document.getElementById(oInstance.sMONTHID).value
sYear=oInstance.currDate.getYear();
newDate=new Date(sYear,sMonth,sDay);
oInstance.Refresh(new Date());
}
function CalendarTodayClick(oInstance) /// "Today" button Change
{
oInstance.Refresh(new Date());
}
function getDateString(oInputSrc,oInstance)
{
if(oInputSrc&&oInstance)
{
// CalendarDiv=document.all[oInstance.sDIVID];
CalendarDiv = document.getElementById(oInstance.sDIVID);
oInstance.oTaget=oInputSrc;
if(document.all){
//CalendarDiv.style.pixelLeft=CalendargetPos(oInputSrc,"Left")+90+oInputSrc.offsetWidth;
//CalendarDiv.style.pixelTop=CalendargetPos(oInputSrc,"Top")-25+oInputSrc.offsetHeight;
CalendarDiv.style.pixelLeft=CalendargetPos(oInputSrc,"Left");
CalendarDiv.style.pixelTop=CalendargetPos(oInputSrc,"Top") + oInputSrc.offsetHeight;
}else{
//CalendarDiv.style.left=CalendargetPos(oInputSrc,"Left") - 134+oInputSrc.offsetWidth + "px";
CalendarDiv.style.left=CalendargetPos(oInputSrc,"Left") + "px";
CalendarDiv.style.top=CalendargetPos(oInputSrc,"Top") + oInputSrc.offsetHeight + "px";
}
CalendarDiv.style.display=(CalendarDiv.style.display=="none")?"":"none";
}
glbObjPointer = oInputSrc;
}
function CalendarCellSetCss(sMode,oCell) /// Set Cell Css
{
// sMode
// 0: OnMouserOut 1: OnMouseOver
if(sMode)
{
oCell.style.border="1px solid #FEFEFE";//日选择背景外框颜色(白)
oCell.style.backgroundColor="#C2C2C2";//日选择背景内框颜色(灰)
}
else
{
oCell.style.border="1px solid #FFFFFF";
oCell.style.backgroundColor="#FFFFFF";
}
}
function CalendarGetMaxDay(nowYear,nowMonth) /// Get MaxDay of current month
{
var nextMonth,nextYear,currDate,nextDate,theMaxDay
nextMonth=nowMonth+1;
if(nextMonth>11)
{
nextYear=nowYear+1;
nextMonth=0;
}
else
{
nextYear=nowYear;
}
currDate=new Date(nowYear,nowMonth,1);
nextDate=new Date(nextYear,nextMonth,1);
theMaxDay=(nextDate-currDate)/(24*60*60*1000);
return theMaxDay;
}
function CalendargetPos(el,ePro) /// Get Absolute Position
{
var ePos=0;
while(el!=null)
{
ePos+=el["offset"+ePro];
el=el.offsetParent;
}
return ePos;
}
function CalendarDblNum(num)
{
if(num<10)
return "0"+num;
else
return num;
}
function CalendarCancel(oInstance) ///Cancel
{
//CalendarDiv=document.all[oInstance.sDIVID];
CalendarDiv = document.getElementById(oInstance.sDIVID);
CalendarDiv.style.display="none";
}
//var oCalendarEn=new PopupCalendar("oCalendarEn"); //\u521d\u59cb\u5316\u63a7\u4ef6\u65f6,\u8bf7\u7ed9
\u51fa\u5b9e\u4f8b\u540d\u79f0\u5982:oCalendarEn
//oCalendarEn.Init();
var oCalendarChs=new PopupCalendar("oCalendarChs"); //\u521d\u59cb\u5316\u63a7\u4ef6\u65f6,\u8bf7\u7ed9
\u51fa\u5b9e\u4f8b\u540d\u79f0:oCalendarChs
oCalendarChs.weekDaySting=new Array("\u65e5","\u4e00","\u4e8c","\u4e09","\u56db","\u4e94","\u516d");
oCalendarChs.monthSting=new Array("\u4e00\u6708","\u4e8c\u6708","\u4e09\u6708","\u56db\u6708","\u4e94
\u6708","\u516d\u6708","\u4e03\u6708","\u516b\u6708","\u4e5d\u6708","\u5341\u6708","\u5341\u4e00\u6708","\u5341
\u4e8c\u6708");
oCalendarChs.oBtnTodayTitle="\u4eca\u5929";
oCalendarChs.oBtnCancelTitle="\u53d6\u6d88";
oCalendarChs.oBtnCleanTitle="\u6e05\u7a7a";
oCalendarChs.Init();function fillZero(num, count) {
var strNum =num.toString();
for (var i = 0; i < count - strNum.length(); i++) {
strNum = '0' + strNum;
}
return strNum;
}String(100+num).slice(1)
特别说明:如网页特效代码中有引用图片文件等,请自己下载到本地调试!
