|
藍森林 http://www.lslnet.com 2006年8月25日 8:28
求簡單通用的input日期的腳本
有沒有簡單通用一些的呢? |
[html]
<SCRIPT LANGUAGE="JavaScript">
<!--
//有效的時間範圍
var date_start,date_end,g_object
var today = new Date();
var separator="-";
var inover=false;
//mode :時間變換的類型0-年 1-月 2-直接選擇月
function change_date(temp,mode)
{
var t_month,t_year
if (mode){
if(mode==1)
t_month=parseInt(cele_date_month.value,10)+parseInt(temp,10);
else
t_month=parseInt(temp)
if (t_month<cele_date_month.options(0).text) {
cele_date_month.value=cele_date_month.options(cele_date_month.length-1).text;
change_date(parseInt(cele_date_year.value,10)-1,0);
}
else{
if (t_month>cele_date_month.options(cele_date_month.length-1).text){
cele_date_month.value=cele_date_month.options(0).text;
change_date(parseInt(cele_date_year.value,10)+1,0);
}
else
{cele_date_month.value=t_month;
set_cele_date(cele_date_year.value,cele_date_month.value);
}
}
}
else{
t_year=parseInt(temp,10);
if (t_year<cele_date_year.options(0).text) {
cele_date_year.value=cele_date_year.options(0).text;
set_cele_date(cele_date_year.value,1);
}
else{
if (parseInt(t_year,10)>parseInt(cele_date_year.options(cele_date_year.length-1).text,10)){
cele_date_year.value=cele_date_year.options(cele_date_year.length-1).text;
set_cele_date(cele_date_year.value,12);
}
else
{cele_date_year.value=t_year;
set_cele_date(cele_date_year.value,cele_date_month.value);
}
}
}
/*********2002-02-01 MODIFY BY WING **************/
window.cele_date.focus();
/****************MODIFY END***********************/
}
//初始化日曆
function init(d_start,d_end)
{
var temp_str;
var i=0
var j=0
date_start=new Date(2000,7,1)
date_end=new Date(2004,8,1)
//必須要有內容(奇怪)
/*************************2002-02-01 MODIFY BY WING *********************************************************************************/
document.writeln("<div name=\"cele_date\" id=\"cele_date\" style=\"display:none\" style=\"LEFT: 69px; POSITION: absolute; TOP: 159px;Z-INDEX:99\" onClick=\"event.cancelBubble=true;\" onBlur=\"hilayer()\" onMouseout=\"lostlayerfocus()\"> </div>");
/*******************************************MODIFY END*******************************************************************************/
window.cele_date.innerHTML="";
temp_str="<table border=\"1\" bgcolor=\"#4682b4\" bordercolor=\"white\"><tr><td colspan=7 onmouseover=\"overcolor(this)\">";
temp_str+="<input type=\"Button\" value=\"<<\" onclick=\"change_date(-1,1)\" onmouseover=\"getlayerfocus()\" style=\"color: #FFFFFF; background-color: #5d7790; cursor: hand\"> ";//左面的箭頭
/**************************2002-02-01 MODIFY BY WING ********************************************************************************/
/*temp_str+="<input type=\"Button\" value=\"<<\" onclick=\"change_date(-1,1)\" > ";//左面的箭頭 */
/************************************************************************************************************************************/
temp_str+=""//年
temp_str+="<select name=\"cele_date_year\" id=\"cele_date_year\" language=\"javascript\" onchange=\"change_date(this.value,0)\" onmouseover=\"getlayerfocus()\" onblur=\"getlayerfocus()\" style=\"font-size: 9pt; border: 1px #666666 outset; background-color: #F4F8FB\">"
/**************************2002-02-01 MODIFY BY WING ********************************************************************************/
/*temp_str+="<select name=\"cele_date_year\" id=\"cele_date_year\" language=\"javascript\" onchange=\"change_date(this.value,0)\">" */
/************************************************************************************************************************************/
for (i=2000;i<=2020;i++)
{
temp_str+="<OPTION value=\""+i.toString()+"\">"+i.toString()+"</OPTION>";
}
temp_str+="</select> ";
temp_str+=""//月
temp_str+="<select name=\"cele_date_month\" id=\"cele_date_month\" language=\"javascript\" onchange=\"change_date(this.value,2)\" onmouseover=\"getlayerfocus()\" onblur=\"getlayerfocus()\" style=\"font-size: 9pt; border: 1px #666666 outset; background-color: #F4F8FB\">"
/**************************2002-02-01 MODIFY BY WING **********************************************************************************/
/*temp_str+="<select name=\"cele_date_month\" id=\"cele_date_month\" language=\"javascript\" onchange=\"change_date(this.value,2)\">" */
/**************************************************************************************************************************************/
for (i=1;i<=12;i++)
{
temp_str+="<OPTION value=\""+i.toString()+"\">"+i.toString()+"</OPTION>";
}
temp_str+="</select> ";
temp_str+=""//右箭頭
temp_str+="<input type=\"Button\" value=\">>\" onclick=\"change_date(1,1)\" onmouseover=\"getlayerfocus()\" style=\"color: #FFFFFF; background-color: #5d7790; cursor: hand\">";
/**************************2002-02-01 MODIFY BY WING ********************************************************************************/
/*temp_str+="<input type=\"Button\" value=\">>\" onclick=\"change_date(1,1)\">"; */
/************************************************************************************************************************************/
temp_str+="</td></tr><tr><td onmouseover=\"overcolor(this)\">"
temp_str+="<font color=red>Su</font></td><td>";temp_str+="Mo</td><td>"; temp_str+="Tu</td><td>"; temp_str+="We</td><td>"
temp_str+="Th</td><td>";temp_str+="Fr</td><td>"; temp_str+="Sa</td></tr>";
for (i=1 ;i<=6 ;i++)
{
temp_str+="<tr>";
for(j=1;j<=7;j++){
temp_str+="<td name=\"c"+i+"_"+j+"\"id=\"c"+i+"_"+j+"\" style=\"CURSOR: hand\" style=\"COLOR:#000000\" language=\"javascript\" onmouseover=\"overcolor(this)\" onmouseout=\"outcolor(this)\" onclick=\"td_click(this)\"> </td>"
}
temp_str+="</tr>"
}
temp_str+="</td></tr></table>";
window.cele_date.innerHTML=temp_str;
}
function set_cele_date(year,month)
{
var i,j,p,k
var nd=new Date(year,month-1,1);
event.cancelBubble=true;
cele_date_year.value=year;
cele_date_month.value=month;
k=nd.getDay()-1
var temp;
for (i=1;i<=6;i++)
for(j=1;j<=7;j++)
{
eval("c"+i+"_"+j+".innerHTML=\"\"");
eval("c"+i+"_"+j+".bgColor=\"#4682b4\"");
eval("c"+i+"_"+j+".style.cursor=\"hand\"");
}
while(month-1==nd.getMonth())
{ j=(nd.getDay() +1);
p=parseInt((nd.getDate()+k) / 7)+1;
eval("c"+p+"_"+j+".innerHTML="+"\""+nd.getDate()+"\"");
if ((nd.getDate()==today.getDate())&&(cele_date_month.value==today.getMonth()+1)&&(cele_date_year.value==today.getYear())){
eval("c"+p+"_"+j+".bgColor=\"#EFFB64\"");
}
if (nd>date_end || nd<date_start)
{
eval("c"+p+"_"+j+".bgColor=\"#FF9999\"");
eval("c"+p+"_"+j+".style.cursor=\"text\"");
}
nd=new Date(nd.valueOf() + 86400000)
}
}
//s_object:點擊的對象;d_start-d_end有效的時間區段;需要存放值的控件;
function show_cele_date(eP,d_start,d_end,t_object)
{
window.cele_date.style.display="";
window.cele_date.style.zIndex=99
var s,cur_d
var eT = eP.offsetTop;
var eH = eP.offsetHeight+eT;
var dH = window.cele_date.style.pixelHeight;
var sT = document.body.scrollTop;
var sL = document.body.scrollLeft;
event.cancelBubble=true;
window.cele_date.style.posLeft = event.clientX-event.offsetX+sL-5;
window.cele_date.style.posTop = event.clientY-event.offsetY+eH+sT-5;
if (window.cele_date.style.posLeft+window.cele_date.clientWidth>document.body.clientWidth) window.cele_date.style.posLeft+=eP.offsetWidth-window.cele_date.clientWidth;
//if (window.cele_date.style.posTop+window.cele_date.clientHeight>document.body.clientHeight) window.cele_date.style.posTop-=(eP.offsetHeight+window.cele_date.clientHeight+5);
if (d_start!=""){
if (d_start=="today"){
date_start=new Date(today.getYear(),today.getMonth(),today.getDate());
}else{
s=d_start.split(separator);
date_start=new Date(s[0],s[1]-1,s[2]);
}
}else{
date_start=new Date(1900,1,1);
}
if (d_end!=""){
s=d_end.split(separator);
date_end=new Date(s[0],s[1]-1,s[2]);
}else{
date_end=new Date(3000,1,1);
}
g_object=t_object
cur_d=new Date()
set_cele_date(cur_d.getYear(),cur_d.getMonth()+1);
window.cele_date.style.display="block";
/***************2002-02-01 MODIFY BY WING ***********/
window.cele_date.focus();
/****************MODIFY END**************************/
}
function td_click(t_object)
{
var t_d
if (parseInt(t_object.innerHTML,10)>=1 && parseInt(t_object.innerHTML,10)<=31 )
{ t_d=new Date(cele_date_year.value,cele_date_month.value-1,t_object.innerHTML)
if (t_d<=date_end && t_d>=date_start)
{
var year = cele_date_year.value;
var month = cele_date_month.value;
var day = t_object.innerHTML;
if (parseInt(month)<10) month = "0" + month;
if (parseInt(day)<10) day = "0" + day;
g_object.value=year+separator+month+separator+day;
window.cele_date.style.display="none";};
}
}
function h_cele_date()
{
window.cele_date.style.display="none";
}
function overcolor(obj)
{
if (obj.style.cursor=="hand") obj.style.color = "#FFFFFF";
/*********** 2002-02-01 MODIFY BY WING *****/
inover=true;
window.cele_date.focus();
/************* MODIFY END ******************/
}
function outcolor(obj)
{
obj.style.color = "#000000";
/*********** 2002-02-01 MODIFY BY WING *****/
inover=false;
/************* MODIFY END ******************/
}
function getNow(o){
var Stamp=new Date();
var year = Stamp.getYear();
var month = Stamp.getMonth()+1;
var day = Stamp.getDate();
if(month<10){
month="0"+month;
}
if(day<10){
day="0"+day;
}
o.value=year+separator+month+separator+day;
}
/*********** 2002-02-01 MODIFY BY WING **ADD THREE FUNCTION TO CONTROL THE DIV FOCUS***/
function hilayer()
{
if (inover==false)
{
var lay=document.all.cele_date;
lay.style.display="none";
}
}
function getlayerfocus()
{
inover=true;
}
function lostlayerfocus()
{
inover=false;
}
/***************************MODIFY END************************************************/
//-->
</SCRIPT>
<script language="javascript">
init();
</script>
<center>
<input type="text" name="Last_Update_Date" size="26" maxlength="19" readonly>
<input type="button" name="change2" value=".." onclick="show_cele_date(change2,'','',Last_Update_Date)">
[/html] |
代碼有問題呀 |
上面那個有錯誤。
[html]
<form name="form1" method="post" action="">
<p>
<input type="text" name="textfield" onFocus="CalendarWebControl.show(this,true,this.value);">
日期時間輸入</p>
<p>
<input type="text" name="textfield2" onFocus="CalendarWebControl.show(this,false,this.value);">
日期輸入</p>
</form>
<script language="javascript">
function atCalendarControl(){
var calendar=this;
this.calendarPad=null;
this.prevMonth=null;
this.nextMonth=null;
this.prevYear=null;
this.nextYear=null;
this.goToday=null;
this.calendarClose=null;
this.calendarAbout=null;
this.head=null;
this.body=null;
this.today=[];
this.currentDate=[];
this.sltDate;
this.target;
this.source;
/************** 加入日曆底板及陰影 *********************/
this.addCalendarPad=function(){
document.write("<div id='divCalendarpad' style='position:absolute;top:100;left:0;width:255;height:167;display:none;'>");
document.write("<iframe frameborder=0 height=187 width=255></iframe>");
document.write("<div style='position:absolute;top:2;left:2;width:250;height:194;background-color:#336699;'></div>");
document.write("</div>");
calendar.calendarPad=document.all.divCalendarpad;
}
/************** 加入日曆面板 *********************/
this.addCalendarBoard=function(){
var BOARD=this;
var divBoard=document.createElement("div");
calendar.calendarPad.insertAdjacentElement("beforeEnd",divBoard);
divBoard.style.cssText="position:absolute;top:0;left:0;width:250;height:194;border:0 outset;background-color:buttonface;";
var tbBoard=document.createElement("table");
divBoard.insertAdjacentElement("beforeEnd",tbBoard);
tbBoard.style.cssText="position:absolute;top:2;left:2;width:248;height:10;font-size:9pt;";
tbBoard.cellPadding=0;
tbBoard.cellSpacing=1;
/************** 設置各功能按鈕的功能 *********************/
/*********** Calendar About Button ***************/
trRow = tbBoard.insertRow(0);
calendar.calendarAbout=calendar.insertTbCell(trRow,0,"-","center");
calendar.calendarAbout.title="幫助 快捷鍵:H";
calendar.calendarAbout.onclick=function(){calendar.about();}
/*********** Calendar Head ***************/
tbCell=trRow.insertCell(1);
tbCell.colSpan=5;
tbCell.bgColor="#99CCFF";
tbCell.align="center";
tbCell.style.cssText = "cursor:default";
calendar.head=tbCell;
/*********** Calendar Close Button ***************/
tbCell=trRow.insertCell(2);
calendar.calendarClose = calendar.insertTbCell(trRow,2,"x","center");
calendar.calendarClose.title="關閉 快捷鍵:ESC";
calendar.calendarClose.onclick=function(){calendar.hide();}
/*********** Calendar PrevYear Button ***************/
trRow = tbBoard.insertRow(1);
calendar.prevYear = calendar.insertTbCell(trRow,0,"<<","center");
calendar.prevYear.title="上一年 快捷鍵:↑";
calendar.prevYear.onmousedown=function(){
calendar.currentDate[0]--;
calendar.show(calendar.target,calendar.returnTime,calendar.currentDate[0]+"-"+calendar.currentDate[1]+"-"+calendar.currentDate[2],calendar.source);
}
/*********** Calendar PrevMonth Button ***************/
calendar.prevMonth = calendar.insertTbCell(trRow,1,"<","center");
calendar.prevMonth.title="上一月 快捷鍵:←";
calendar.prevMonth.onmousedown=function(){
calendar.currentDate[1]--;
if(calendar.currentDate[1]==0){
calendar.currentDate[1]=12;
calendar.currentDate[0]--;
}
calendar.show(calendar.target,calendar.returnTime,calendar.currentDate[0]+"-"+calendar.currentDate[1]+"-"+calendar.currentDate[2],calendar.source);
}
/*********** Calendar Today Button ***************/
calendar.goToday = calendar.insertTbCell(trRow,2,"今天","center",3);
calendar.goToday.title="選擇今天 快捷鍵:T";
calendar.goToday.onclick=function(){
if(calendar.returnTime)
calendar.sltDate=calendar.today[0]+"-"+calendar.today[1]+"-"+calendar.today[2]+" "+calendar.today[3]+":"+calendar.today[4]
else
calendar.sltDate=calendar.today[0]+"-"+calendar.today[1]+"-"+calendar.today[2];
calendar.target.value=calendar.sltDate;
calendar.hide();
//calendar.show(calendar.target,calendar.today[0]+"-"+calendar.today[1]+"-"+calendar.today[2],calendar.source);
}
/*********** Calendar NextMonth Button ***************/
calendar.nextMonth = calendar.insertTbCell(trRow,3,">","center");
calendar.nextMonth.title="下一月 快捷鍵:→";
calendar.nextMonth.onmousedown=function(){
calendar.currentDate[1]++;
if(calendar.currentDate[1]==13){
calendar.currentDate[1]=1;
calendar.currentDate[0]++;
}
calendar.show(calendar.target,calendar.returnTime,calendar.currentDate[0]+"-"+calendar.currentDate[1]+"-"+calendar.currentDate[2],calendar.source);
}
/*********** Calendar NextYear Button ***************/
calendar.nextYear = calendar.insertTbCell(trRow,4,">>","center");
calendar.nextYear.title="下一年 快捷鍵:↓";
calendar.nextYear.onmousedown=function(){
calendar.currentDate[0]++;
calendar.show(calendar.target,calendar.returnTime,calendar.currentDate[0]+"-"+calendar.currentDate[1]+"-"+calendar.currentDate[2],calendar.source);
}
trRow = tbBoard.insertRow(2);
var cnDateName = new Array("日","一","二","三","四","五","六");
for (var i = 0; i < 7; i++) {
tbCell=trRow.insertCell(i)
tbCell.innerText=cnDateName[i];
tbCell.align="center";
tbCell.width=35;
tbCell.style.cssText="cursor:default;border:1 solid #99CCCC;background-color:#99CCCC;";
}
/*********** Calendar Body ***************/
trRow = tbBoard.insertRow(3);
tbCell=trRow.insertCell(0);
tbCell.colSpan=7;
tbCell.height=97;
tbCell.vAlign="top";
tbCell.bgColor="#F0F0F0";
var tbBody=document.createElement("table");
tbCell.insertAdjacentElement("beforeEnd",tbBody);
tbBody.style.cssText="position:relative;top:0;left:0;width:245;height:103;font-size:9pt;"
tbBody.cellPadding=0;
tbBody.cellSpacing=1;
calendar.body=tbBody;
/*********** Time Body ***************/
trRow = tbBoard.insertRow(4);
tbCell=trRow.insertCell(0);
calendar.prevHours = calendar.insertTbCell(trRow,0,"-","center");
calendar.prevHours.title="小時調整 快捷鍵:Home";
calendar.prevHours.onmousedown=function(){
calendar.currentDate[3]--;
if(calendar.currentDate[3]==-1) calendar.currentDate[3]=23;
calendar.bottom.innerText=calendar.formatTime(calendar.currentDate[3])+":"+calendar.formatTime(calendar.currentDate[4]);
}
tbCell=trRow.insertCell(1);
calendar.nextHours = calendar.insertTbCell(trRow,1,"+","center");
calendar.nextHours.title="小時調整 快捷鍵:End";
calendar.nextHours.onmousedown=function(){
calendar.currentDate[3]++;
if(calendar.currentDate[3]==24) calendar.currentDate[3]=0;
calendar.bottom.innerText=calendar.formatTime(calendar.currentDate[3])+":"+calendar.formatTime(calendar.currentDate[4]);
}
tbCell=trRow.insertCell(2);
tbCell.colSpan=3;
tbCell.bgColor="#99CCFF";
tbCell.align="center";
tbCell.style.cssText = "cursor:default";
calendar.bottom=tbCell;
tbCell=trRow.insertCell(3);
calendar.prevMinutes = calendar.insertTbCell(trRow,3,"-","center");
calendar.prevMinutes.title="分鐘調整 快捷鍵:PageUp";
calendar.prevMinutes.onmousedown=function(){
calendar.currentDate[4]--;
if(calendar.currentDate[4]==-1) calendar.currentDate[4]=59;
calendar.bottom.innerText=calendar.formatTime(calendar.currentDate[3])+":"+calendar.formatTime(calendar.currentDate[4]);
}
tbCell=trRow.insertCell(4);
calendar.nextMinutes = calendar.insertTbCell(trRow,4,"+","center");
calendar.nextMinutes.title="分鐘調整 快捷鍵:PageDown";
calendar.nextMinutes.onmousedown=function(){
calendar.currentDate[4]++;
if(calendar.currentDate[4]==60) calendar.currentDate[4]=0;
calendar.bottom.innerText=calendar.formatTime(calendar.currentDate[3])+":"+calendar.formatTime(calendar.currentDate[4]);
}
}
/************** 加入功能按鈕公共樣式 *********************/
this.insertTbCell=function(trRow,cellIndex,TXT,trAlign,tbColSpan){
var tbCell=trRow.insertCell(cellIndex);
if(tbColSpan!=undefined) tbCell.colSpan=tbColSpan;
var btnCell=document.createElement("button");
tbCell.insertAdjacentElement("beforeEnd",btnCell);
btnCell.value=TXT;
btnCell.style.cssText="width:100%;border:1 outset;background-color:buttonface;";
btnCell.onmouseover=function(){
btnCell.style.cssText="width:100%;border:1 outset;background-color:#F0F0F0;";
}
btnCell.onmouseout=function(){
btnCell.style.cssText="width:100%;border:1 outset;background-color:buttonface;";
}
// btnCell.onmousedown=function(){
// btnCell.style.cssText="width:100%;border:1 inset;background-color:#F0F0F0;";
// }
btnCell.onmouseup=function(){
btnCell.style.cssText="width:100%;border:1 outset;background-color:#F0F0F0;";
}
btnCell.onclick=function(){
btnCell.blur();
}
return btnCell;
}
this.setDefaultDate=function(){
var dftDate=new Date();
calendar.today[0]=dftDate.getYear();
calendar.today[1]=dftDate.getMonth()+1;
calendar.today[2]=dftDate.getDate();
calendar.today[3]=dftDate.getHours();
calendar.today[4]=dftDate.getMinutes();
}
/****************** Show Calendar *********************/
this.show=function(targetObject,returnTime,defaultDate,sourceObject){
if(targetObject==undefined) {
alert("未設置目標對像. \n方法: ATCALENDAR.show(obj 目標對像,boolean 是否返回時間,string 默認日期,obj 點擊對像);\n\n目標對像:接受日期返回值的對象.\n默認日期:格式為\"yyyy-mm-dd\",缺省為當前日期.\n點擊對像:點擊這個對象彈出calendar,默認為目標對像.\n");
return false;
}
else calendar.target=targetObject;
if(sourceObject==undefined) calendar.source=calendar.target;
else calendar.source=sourceObject;
if(returnTime) calendar.returnTime=true;
else calendar.returnTime=false;
var firstDay;
var Cells=new Array();
if(defaultDate==undefined || defaultDate==""){
var theDate=new Array();
calendar.head.innerText = calendar.today[0]+"-"+calendar.formatTime(calendar.today[1])+"-"+calendar.formatTime(calendar.today[2]);
calendar.bottom.innerText = calendar.formatTime(calendar.today[3])+":"+calendar.formatTime(calendar.today[4]);
theDate[0]=calendar.today[0]; theDate[1]=calendar.today[1]; theDate[2]=calendar.today[2];
theDate[3]=calendar.today[3]; theDate[4]=calendar.today[4];
}
else{
var Datereg=/^\d{4}-\d{1,2}-\d{2}$/
var DateTimereg=/^(\d{1,4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2})$/
if(!defaultDate.match(Datereg)&&!defaultDate.match(DateTimereg)){
alert("默認日期(時間)的格式不正確!\t\n\n默認可接受格式為:\n1、yyyy-mm-dd \n2、yyyy-mm-dd hh:mm");
calendar.setDefaultDate();
return;
}
if(defaultDate.match(Datereg)) defaultDate=defaultDate+" "+calendar.today[3]+":"+calendar.today[4];
var strDateTime=defaultDate.match(DateTimereg);
var theDate=new Array(4)
theDate[0]=strDateTime[1];
theDate[1]=strDateTime[2];
theDate[2]=strDateTime[3];
theDate[3]=strDateTime[4];
theDate[4]=strDateTime[5];
calendar.head.innerText = theDate[0]+"-"+calendar.formatTime(theDate[1])+"-"+calendar.formatTime(theDate[2]);
calendar.bottom.innerText = calendar.formatTime(theDate[3])+":"+calendar.formatTime(theDate[4]);
}
calendar.currentDate[0]=theDate[0];
calendar.currentDate[1]=theDate[1];
calendar.currentDate[2]=theDate[2];
calendar.currentDate[3]=theDate[3];
calendar.currentDate[4]=theDate[4];
theFirstDay=calendar.getFirstDay(theDate[0],theDate[1]);
theMonthLen=theFirstDay+calendar.getMonthLen(theDate[0],theDate[1]);
//calendar.setEventKey();
calendar.calendarPad.style.display="";
var theRows = Math.ceil((theMonthLen)/7);
//清除舊的日曆;
while (calendar.body.rows.length > 0) {
calendar.body.deleteRow(0)
}
//建立新的日曆;
var n=0;day=0;
for(i=0;i<theRows;i++){
theRow=calendar.body.insertRow(i);
for(j=0;j<7;j++){
n++;
if(n>theFirstDay && n<=theMonthLen){
day=n-theFirstDay;
calendar.insertBodyCell(theRow,j,day);
}
else{
var theCell=theRow.insertCell(j);
theCell.style.cssText="background-color:#F0F0F0;cursor:default;";
}
}
}
//****************調整日曆位置**************//
var offsetPos=calendar.getAbsolutePos(calendar.source);//計算對象的位置;
if((document.body.offsetHeight-(offsetPos.y+calendar.source.offsetHeight-document.body.scrollTop))<calendar.calendarPad.style.pixelHeight){
var calTop=offsetPos.y-calendar.calendarPad.style.pixelHeight-calendar.source.offsetHeight;
}
else{
var calTop=offsetPos.y+calendar.source.offsetHeight;
}
if((document.body.offsetWidth-(offsetPos.x+calendar.source.offsetWidth-document.body.scrollLeft))>calendar.calendarPad.style.pixelWidth){
var calLeft=offsetPos.x;
}
else{
var calLeft=calendar.source.offsetLeft+calendar.source.offsetWidth;
}
//alert(offsetPos.x);
calendar.calendarPad.style.pixelLeft=calLeft;
calendar.calendarPad.style.pixelTop=calTop;
}
/****************** 計算對象的位置 *************************/
this.getAbsolutePos = function(el) {
var r = { x: el.offsetLeft, y: el.offsetTop };
if (el.offsetParent) {
var tmp = calendar.getAbsolutePos(el.offsetParent);
r.x += tmp.x;
r.y += tmp.y;
}
return r;
};
//************* 插入日期單元格 **************/
this.insertBodyCell=function(theRow,j,day,targetObject){
var theCell=theRow.insertCell(j);
if(j==0) var theBgColor="#FF9999";
else var theBgColor="#FFFFFF";
if(day==calendar.currentDate[2]) var theBgColor="#CCCCCC";
if(day==calendar.today[2]) var theBgColor="#99FFCC";
theCell.bgColor=theBgColor;
theCell.innerText=day;
theCell.align="center";
theCell.width=35;
theCell.style.cssText="border:1 solid #CCCCCC;cursor:hand;";
theCell.onmouseover=function(){
theCell.bgColor="#FFFFCC";
theCell.style.cssText="border:1 outset;cursor:hand;";
}
theCell.onmouseout=function(){
theCell.bgColor=theBgColor;
theCell.style.cssText="border:1 solid #CCCCCC;cursor:hand;";
}
theCell.onmousedown=function(){
theCell.bgColor="#FFFFCC";
theCell.style.cssText="border:1 inset;cursor:hand;";
}
theCell.onclick=function(){
if(calendar.returnTime)
calendar.sltDate=calendar.currentDate[0]+"-"+calendar.formatTime(calendar.currentDate[1])+"-"+calendar.formatTime(day)+" "+calendar.formatTime(calendar.currentDate[3])+":"+calendar.formatTime(calendar.currentDate[4])
else
calendar.sltDate=calendar.currentDate[0]+"-"+calendar.formatTime(calendar.currentDate[1])+"-"+calendar.formatTime(day);
calendar.target.value=calendar.sltDate;
calendar.hide();
}
}
/************** 取得月份的第一天為星期幾 *********************/
this.getFirstDay=function(theYear, theMonth){
var firstDate = new Date(theYear,theMonth-1,1);
return firstDate.getDay();
}
/************** 取得月份共有幾天 *********************/
this.getMonthLen=function(theYear, theMonth) {
theMonth--;
var oneDay = 1000 * 60 * 60 * 24;
var thisMonth = new Date(theYear, theMonth, 1);
var nextMonth = new Date(theYear, theMonth + 1, 1);
var len = Math.ceil((nextMonth.getTime() - thisMonth.getTime())/oneDay);
return len;
}
/************** 隱藏日曆 *********************/
this.hide=function(){
//calendar.clearEventKey();
calendar.calendarPad.style.display="none";
}
/************** 從這裡開始 *********************/
this.setup=function(defaultDate){
calendar.addCalendarPad();
calendar.addCalendarBoard();
calendar.setDefaultDate();
}
/************** 格式化時間 *********************/
this.formatTime = function(str) {
str = ("00"+str);
return str.substr(str.length-2);
}
/************** 關於AgetimeCalendar *********************/
this.about=function(){
var strAbout = "\nWeb 日曆選擇輸入控件操作說明:\n\n";
strAbout+="-\t: 關於\n";
strAbout+="x\t: 隱藏\n";
strAbout+="<<\t: 上一年\n";
strAbout+="<\t: 上一月\n";
strAbout+="今日\t: 返回當天日期\n";
strAbout+=">\t: 下一月\n";
strAbout+="<<\t: 下一年\n";
strAbout+="\nWeb日曆選擇輸入控件\tVer:v1.0\t\nDesigned By:Baby2008 \t\t2004.11.23\t\n";
alert(strAbout);
}
document.onkeydown=function(){
if(calendar.calendarPad.style.display=="none"){
window.event.returnValue= true;
return true ;
}
switch(window.event.keyCode){
case 27 : calendar.hide(); break; //ESC
case 37 : calendar.prevMonth.onmousedown(); break;//←
case 38 : calendar.prevYear.onmousedown();break; //↑
case 39 : calendar.nextMonth.onmousedown(); break;//→
case 40 : calendar.nextYear.onmousedown(); break;//↓
case 84 : calendar.goToday.onclick(); break;//T
case 88 : calendar.hide(); break; //X
case 72 : calendar.about(); break; //H
case 36 : calendar.prevHours.onmousedown(); break;//Home
case 35 : calendar.nextHours.onmousedown(); break;//End
case 33 : calendar.prevMinutes.onmousedown();break; //PageUp
case 34 : calendar.nextMinutes.onmousedown(); break;//PageDown
}
window.event.keyCode = 0;
window.event.returnValue= false;
}
calendar.setup();
}
var CalendarWebControl = new atCalendarControl();
</script>
[/html] |
按鈕有個空白的怎麼搞的,兄弟加油啊 |
|