日期:2014-05-16 浏览次数:20491 次
// 主调用函数是 setday(this,[object])和setday(this),[object]是控件输出的控件名,举两个例子:
// 一、 <input name=txt> <input type=button value=setday onclick="setday(this,document.all.txt)">
// 二、 <input onfocus="setday(this)">
var outObject;
var outButton; //点击的按钮
var outDate=""; //存放对象的日期
var odatelayer=window.frames.endDateLayer.document.all;//存放日历对象
var odatelayer=window.endDateLayer.document.all;
function setday(tt,obj) //主调函数
{
if (arguments.length > 2){alert("对不起!传入本控件的参数太多!");return;}
if (arguments.length == 0){alert("对不起!您没有传回本控件任何参数!");return;}
var dads = document.all.endDateLayer.style;
var th = tt;
var ttop = tt.offsetTop; //TT控件的定位点高
var thei = tt.clientHeight; //TT控件本身的高
var tleft = tt.offsetLeft; //TT控件的定位点宽
var ttyp = tt.type; //TT控件的类型
while (tt = tt.offsetParent){ttop+=tt.offsetTop; tleft+=tt.offsetLeft;}
dads.top = (ttyp=="image") ? ttop+thei : ttop+thei+6;
dads.left = tleft;
// outObject = (arguments.length == 1) ? th : obj;
// outButton = (arguments.length == 1) ? null : th; //设定外部点击的按钮
outObject = th;
outButton = null;
//根据当前输入框的日期显示日历的年月
var reg = /^(\d+)-(\d{1,2})-(\d{1,2})/; //不含时间
var r = (arguments.length == 1) ? outObject.value.match(reg) : obj.value.match(reg);
if(r!=null){
r[2]=r[2]-1;
var d=new Date(r[1],r[2],r[3]);
if(d.getFullYear()==r[1] && d.getMonth()==r[2] && d.getDate()==r[3])
{
outDate=d;
parent.meizzTheYear = r[1];
parent.meizzTheMonth = r[2];
parent.meizzTheDate = r[3];
}
else
{
outDate="";
}
meizzSetDay(r[1],r[2]+1);
}
else
{
outDate="";
meizzSetDay(new Date().getFullYear(), new Date().getMonth() + 1);
}
dads.display = '';
meizzWriteHead(meizzTheYear,meizzTheMonth);
try
{
event.returnValue=false;
}
catch (e)
{
//此处排除错误,错误原因暂未找到。
}
}
var meizzTheYear=new Date().getFullYear(); //定义年的变量的初始值
var meizzTheMonth=new Date().getMonth()+1; //定义月的变量的初始值
var meizzTheDate=new Date().getDate(); //定义日的变量的初始值
var meizzWDay=new Array(37); //定义写日期的数组
var meizzWDayT=new Array(37); //定义写日期的数组 第二个月
function meizzWriteHead(yy,mm,ss) //往 head 中写入当前的年与月
{
odatelayer.meizzYearHead.innerText = yy + ".";
odatelayer.meizzMonthHead.innerText = format(mm);
if(mm==12){
var y2=parseInt(yy)+1;
odatelayer.meizzYearHead2.innerText = y2 + ".";
odatelayer.meizzMonthHead2.innerText = 1 ;
}
else{
odatelayer.meizzYearHead2.innerText = yy + ".";
odatelayer.meizzMonthHead2.innerText = format(mm+1) ;
}
}
function meizzSetDay(yy,mm) //主要的写程序**********
{
meizzWriteHead(yy,mm);
//设置当前年月的公共变量为传入值
meizzTheYear=yy;
meizzTheMonth=mm;
//第一个月
for (var i = 0; i < 37; i++){meizzWDay[i]=""}; //将显示框的内容全部清空
var day1 = 1,day2=1,firstday = new Date(yy,mm-1,1).getDay(); //某月第一天的星期几
for (i = firstday; day1 < GetMonthCount(yy,mm)+1; i++) { meizzWDay[i]=day1;day1++; }
for (i = 0; i < 37; i++)
{
var da = eval("odatelayer.meizzDay"+i) //书写新的一个月的日期星期排列
//初始化
da.style.backgro